Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The f attribute of the object returned by numpy.load is not documented #6337

Closed
WarrenWeckesser opened this issue Sep 21, 2015 · 4 comments · Fixed by #24068
Closed

The f attribute of the object returned by numpy.load is not documented #6337

WarrenWeckesser opened this issue Sep 21, 2015 · 4 comments · Fixed by #24068

Comments

@WarrenWeckesser
Copy link
Member

When reading an npz file, numpy.load returns an object that has an attribute called f. f has attributes with names and values corresponding to the names and values of the variables stored in the file. Since f does not have a leading underscore, I assume f is intended to be part of the public API, but f is not documented in the docstring of numpy.load.

Here's an example (see http://stackoverflow.com/questions/32682928/loading-arrays-from-npz-files-in-pythhon/32683037#32683037):

In [1367]: foo = np.load('foo.npz')

In [1368]: foo.keys()
Out[1368]: ['A', 'C', 'B']

In [1369]: foo.f.A
Out[1369]: array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.])

In [1370]: foo.f.B
Out[1370]: 
array([[ 0,  1],
       [-1,  0]])

In [1371]: foo.f.C
Out[1371]: array([ 3.14159265,  2.71828183,  0.57721566])
@charris
Copy link
Member

charris commented Sep 21, 2015

Interesting. f seems a bit obscure. @teoliphant Do you recall what it stood for?

@njsmith
Copy link
Member

njsmith commented Sep 21, 2015

It is described in the docstring for np.lib.npyio.NpzFile (which it looks
like was written by Pauli in 2009, after being implemented by Travis back
in 2007). I assume the name "f" is because it provides "field"-style access
instead of dictionary-style access. The actual semantics are that all
attribute lookups on my_npz.f are converted into getitem lookups on
my_npz.
.
Probably should just be documented in the "Notes" section of the np.load
docstring, next to the other notes on special cases that apply to npz files.

On Sun, Sep 20, 2015 at 8:49 PM, Charles Harris notifications@github.com
wrote:

Interesting. f seems a bit obscure. @teoliphant
https://github.com/teoliphant Do you recall what it stood for?


Reply to this email directly or view it on GitHub
#6337 (comment).

Nathaniel J. Smith -- http://vorpus.org

@WarrenWeckesser
Copy link
Member Author

@njsmith Thanks. I've updated my answer on stackoverflow so that it refers to the NpzFile class for a description of the f attribute.

It would be nice if the documentation could be tweaked so that the NpzFile class docstring becomes part of the online documentation. Then the new note in the load docstring could link to the NpzFile docstring.

@teoliphant
Copy link
Member

@njsmith is basically correct. It stood for "field" and was a short letter so that it took as little typing as possible to provide the ability to translate getattr to getitem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants