Skip to content

DOC: update structured array docs to reflect #6053 - #9056

Merged
charris merged 2 commits into
numpy:masterfrom
ahaldane:structure_docs
Nov 11, 2017
Merged

charris merged 2 commits into
numpy:masterfrom
ahaldane:structure_docs

Conversation

@ahaldane

@ahaldane ahaldane commented May 5, 2017 •

Copy link
Copy Markdown
Member

These are updated structure arrays docs to reflect the changes in #6053.

Don't merge this before #6053.

I'm putting them here now for comments to accompany #6053.

While this PR is open I will maintain an HTML compiled version of these docs at https://ahaldane.github.io/user/basics.rec.html

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not a complaint about this PR, but I don't think I like this behaviour:

>>> np.dtype([('', 'f4'),('f0', 'i4'),('z', 'i8')])
ValueError: field 'f0' occurs more than once

In #9054, I change this in some cases to be "index within the unnamed values". Is that a good thing?

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it might be clearer to show these as >>> dt = np.dtype(...), >>> np.zeros(1, dtype=dt)

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems that arrays.dtypes.rst duplicates a lot of the contents here, and perhaps these should be condensed into a single help page

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Missing comma

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is misleading - we should clarify whether "equivalent dtypes" are such that dt1 == dt2, or if simply np.can_cast(dt1, dt2)

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might be tempting to write this in the following form:

>>> np.zeros(3, dtype=dict(names=    ['col1', 'col2'],
...                        formats=  ['i4','f4'],
...                        offsets=  [0, 4],
...                        itemsize= 12)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Which of course, raises the question of whether np.dtype(**dict) should be added as a shorhand for np.dtype(dict)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Aligning the [...] isn't PEP8. It may take a bit of getting used to but eventually the unaligned versions become easier to read.

@charris

charris commented Sep 21, 2017

Copy link
Copy Markdown
Member

@ahaldane Now that #6053 is in we should get this finished up.

@charris

charris commented Sep 24, 2017

Copy link
Copy Markdown
Member

@ahaldane ping.

@ahaldane

Copy link
Copy Markdown
Member Author

Got it, I'll go over it soon.

@ahaldane
ahaldane force-pushed the structure_docs branch 2 times, most recently from f07ea87 to 3a7f388 Compare September 25, 2017 21:33
@ahaldane

Copy link
Copy Markdown
Member Author

Updated, and ready to read through.

You can view an html version of the current state at https://ahaldane.github.io/user/basics.rec.html

@ahaldane
ahaldane force-pushed the structure_docs branch 2 times, most recently from 602e22d to 5be7def Compare September 27, 2017 23:33
Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"array of length two" and omit the comma. The clause after the comma is essential.

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"for example, interpreting ..."

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

comma after "purposes"

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe "For simple manipulation of tabular data, other pydata projects, such as pandas, xarray, or DataArray, provide higher-level interfaces that may be more suitable."

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"by numpy, but can be manually specified."

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could use a rewrite. I'd probably start a new sentence instead of using "with".

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we want to number subtitles? Maybe a simple enumerated list would do.

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"is an empty string, '', the ..."

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"... string and separated ..."

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"specifications, all of the same length."

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"The optional 'offsets' key is a list of integer byte offsets, one for each field within the structure."

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"... to contain all the fields."

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Commas rather than parenthesis. I don't know when the current parenthetical scourge originated, but it seems to be everywhere these days :-(

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there an example of using a scalar array for the rhs? Does scalar array mean 1-D array here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guess by "scalar array" I mean "unstructured array", will fix.

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there an example of that? Which side has the single field, or is that both sides?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll try to modify the example, perhaps using different variable names,.

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe "The view's" instead of "This view's".

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and <- comma

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this <- the

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could omit "Importantly".

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"such that" <- "so that".

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

though <- thought

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Omit "of".

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What does "equivalent" mean?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

equal, will fix

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

dimension <- dimesions.

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

``True`` ?

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What might be the alternative?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Currently in this case we get:

[1]: a = np.zeros(3, dtype='f,f,f')
[2]: b = np.zeros(3, dtype='f,f')
[3]: a == b
FutureWarning: elementwise == comparison failed and returning scalar instead; this will raise an error or perform elementwise comparison in the future

I'll reword the text to more accurately describe what happens.

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe "The .... operators always return ..."?

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Many or all? Maybe "no other"?

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

which <- that.

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comma not needed.

Comment thread numpy/doc/structured_arrays.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

which <- that

@charris

charris commented Nov 10, 2017

Copy link
Copy Markdown
Member

I'm not sure that we should be using 'title' instead of italicized title or title, the same for other names for parts of the dtype.

NumPy should hire a copy editor, there should be plenty out there in this time of self publishing.

@ahaldane

Copy link
Copy Markdown
Member Author

Updated, thanks a lot. You make a great copy editor!

For the styling of the parts of the dtype, my idea was to use them as normal nouns through most of the document (eg, "the field name is.."), except in the dtype-specification section where I need to make clear the format of the tuple, in which case I write (fieldname, datatype, shape) and refer to the three variables in the tuple in code-styling like fieldname.

@ahaldane
ahaldane force-pushed the structure_docs branch 2 times, most recently from 6ca3fda to 4280fb3 Compare November 10, 2017 02:51
@charris
charris merged commit de26584 into numpy:master Nov 11, 2017
@charris

charris commented Nov 11, 2017

Copy link
Copy Markdown
Member

OK, let's get this in. Thanks Allan.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants