Skip to content

DOC: improve record/structured array nomenclature & guide #5482

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

Merged
merged 1 commit into from
Jan 22, 2015

Conversation

ahaldane
Copy link
Member

This is an improvement, to better differentiate structured arrays, record arrays, and recarrays in the docs. I also added a section to the user guide about record arrays (numpy/doc/structured_arrays.py).

I also discussed these changes on the mailing list in a message "structured arrays, recarrays, and record arrays" on Jan 19 2015. Please look at that for a more detailed rationale.

I define a nomenclature where "structured array" refers to
ndarrays with structured dtype, "record array" refers to modified
ndarrays as created by np.rec.array, and "recarray" refers to ndarrays
viewed as np.recarray.

@@ -432,7 +431,7 @@ Type strings
Both arguments must be convertible to data-type objects in this
case. The *base_dtype* is the data-type object that the new
data-type builds on. This is how you could assign named fields to
any built-in data-type object.
any built-in data-type object, as done in :ref:`record arrays <arrays.classes.rec>`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line may be over long.

@charris
Copy link
Member

charris commented Jan 22, 2015

LGTM apart from several nitpicks. Try to keep line length less than 80 characters.

This update adds a section better describing record arrays in the user
guide (numpy/doc/structured_arrays.py).

It also corrects nomenclature, such that "structured array" refers to
ndarrays with structured dtype, "record array" refers to modified
ndarrays as created by np.rec.array, and "recarray" refers to ndarrays
viewed as np.recarray. See the note at the end of the structured
array user guide.
@ahaldane
Copy link
Member Author

Thanks, I missed those long lines. It should all be fixed now.

charris added a commit that referenced this pull request Jan 22, 2015
DOC: improve record/structured array nomenclature & guide
@charris charris merged commit 5b714c7 into numpy:master Jan 22, 2015
@charris
Copy link
Member

charris commented Jan 22, 2015

Merged, thats @ahaldane.

@ahaldane ahaldane deleted the recordarray_doc branch January 25, 2015 19:14
ahaldane added a commit to ahaldane/numpy that referenced this pull request Jan 30, 2015
In numpy#5483, I solved the problem that a
"recarray" and a "record array" (nomenclature defined in
numpy#5482) looked identical by making
sure that a type's subclass was listed in the repr. However, recarrays
are still represented using the function 'rec.array' even though this
function technically creates record arrays, not recarrays.

So I have updated recarray.__repr__.

Setup:

    >>> a = np.array([(1,'ABC'), (2, "DEF")], dtype=[('foo', int), ('bar', 'S4')])
    >>> recordarr = np.rec.array(a)
    >>> recarr = a.view(np.recarray)

Behavior after numpy#5483:

    >>> recordarr
    rec.array([(1, 'ABC'), (2, 'DEF')],
          dtype=(numpy.record, [('foo', '<i8'), ('bar', 'S4')]))
    >>> recarr
    rec.array([(1, 'ABC'), (2, 'DEF')],
          dtype=[('foo', '<i8'), ('bar', 'S4')])

New Behavior:

    >>> recordarr
    rec.array([(1, 'ABC'), (2, 'DEF')],
          dtype=[('foo', '<i8'), ('bar', '|S4')])
    >>> recarr
    array([(1, 'ABC'), (2, 'DEF')],
          dtype=[('foo', '<i8'), ('bar', 'S4')]).view(numpy.recarray)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants