Skip to content

ENH: Explicitly show keys of .npz file in repr #23319

@rossbar

Description

@rossbar

Proposed new feature or change:

Determining the structure of npz files could be made more intuitive by providing info about keys. A quick example:

>>> np.savez("example.npz", x=np.arange(10), y=np.arange(3))  # An example file with multiple keys
>>> data = np.load("example.npz")
# NpzFile repr doesn't provide info about what the file contains
>>> data
<numpy.lib.npyio.NpzFile at 0x7fbd182567a0>
# Keys returns a KeysView as expected with Python dict-likes, but
# the KeysView repr isn't particularly informative
>>> data.keys()
KeysView(<numpy.lib.npyio.NpzFile object at 0x7fbd182567a0>)
# In order to get explicit info about the key, users have to
# know how to inspect this object
>>> list(data.keys()) 
['x', 'y']
# or,
>>> list(data)
['x', 'y']

I think the user experience with .npz files would be improved by including explicit info about the keys in the NpzFile repr.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions