Skip to content

dtype and struct integer format characters are deceptively similar, yet different #9642

@eric-wieser

Description

@eric-wieser

Picked up via python/cpython#31. This is more of a design mistake than a bug, as it's not clear who made the right decision

# a c long on this platform is indeed 8 bytes
>>> np.dtype('l').itemsize
8  
>>> struct.calcsize('l')
8

# but when an endian mark is specified, l always means 4 bytes to the struct module
>>> np.dtype('>l').itemsize
8
>>> struct.calcsize('>l')
4  

Note that this only occurs on platforms where sizeof(long) == 64, ie not 64-bit windows.

Do we care about consistency with struct? If not, then we need to document that we are not consistent with it.

For searchability: PEP3118

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions