8000 Update table documentation by eerovaher · Pull Request #12011 · astropy/astropy · GitHub
[go: up one dir, main page]

Skip to content

Update table documentation #12011

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
Aug 18, 2021
Merged

Update table documentation #12011

merged 1 commit into from
Aug 18, 2021

Conversation

eerovaher
Copy link
Member
@eerovaher eerovaher commented Aug 3, 2021

Description

Many of the changes add hyperlinks or make sure that function names get rendered as func() instead of func, but there are a few more substantial changes. See the commit messages for details.

Table docs also contain a handful of code examples that have caused problems on Windows and are therefore skipped in doctests. I've re-enabled those tests so that CI could run here because that's the only way I can test the code on Windows. If those tests are still causing problems for Windows then I'll have to redo the last commit of this PR.

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see "When to rebase and squash commits".
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the Extra CI label.
  • Is a change log needed? If yes, did the change log check pass? If no, add the no-changelog-entry-needed label.
  • Is a milestone set? Milestone must be set but astropy-bot check might be missing; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate backport-X.Y.x label(s) before merge.

@eerovaher
Copy link
Member Author

Most of the tests I had re-enabled succeeded, but one still failed on Windows and the 32-bit platform, so I replaced the last commit.

@eerovaher
Copy link
Member Author
eerovaher commented Aug 4, 2021

I tried using .. doctest-skip:: win32 and that allowed the tests to succeed on Windows, but not on 32-bit platform, so it looks like that one test still has to be skipped entirely.

EDIT: The problematic test is

>>> t['a'].mask.nonzero()[0] # doctest: +SKIP
which produces array([1], dtype=np.int64) on Windows, array([1], dtype=np.int32) on the 32-bit platform and array([1]) otherwise.

Copy link
Member
@nstarman nstarman left a comment

Choose a reason for hiding this comment

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

Overall this looks great and like a lot of work!! I didn't have time to go through everything, so if other maintainers could take a look, that would be great. I noted a few places where I think the RST links appear shorter but are both longer and less readable when the docs are compiled. Also, any insight by @astropy/documentation-infrastructure-maintainers on FLOAT_CMP and comparison precision would be useful in keeping some of the table examples readable and now doc-tested.

>>> print(obs_mean) # doctest: +FLOAT_CMP
name mag_b mag_v
---- ------------------ ------------------
M101 15.000000000000002 13.725000000000001
Copy link
Member

Choose a reason for hiding this comment

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

This is machine precision differences. Does +FLOAT_CMP really care about the 16th digit?

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem with tables in doctests is that the number of digits in the output determines the number of dashes in the line preceding the numerical values. So

  name    mag_b
  ---- -----------
  M101        15.0

would succeed, but

  name mag_b
  ---- -----
  M101  15.0

fails. +FLOAT_CMP is working as intended.

I don't think the first example here looks any better than what is in the docs right now.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation. Good to know +FLOAT_CMP is working.
To me the

  name    mag_b
  ---- -----------
  M101        15.0

is better for two reasons. The first is readability. Having some spaces doesn't detract as much as 14 extraneous digits. The second is correctness. 15.0 is the correct number. Presumably a different computer architecture (e.g. big-endian or 32 bit) would have different computer error. +FLOAT_CMP prevents including computer error into the doctest.

Copy link
Member

Choose a reason for hiding this comment

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

In this case I think that the clarity of the example in the original version is more important than having this doctested. I.e. having all those useless digits is just very distracting.

One other option is to set the column formats prior to printing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Setting column formats is the best solution.

Copy link
Member
@nstarman nstarman Aug 18, 2021

Choose a reason for hiding this comment

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

I think we can resolve this thread be #12022 will address this point. Agreed, @taldcroft?

@pllim
Copy link
Member
pllim commented Aug 4, 2021

Amazing! Doc clean-ups are usually not the work people tend to want to do, so thank you so much for tackling this! I'll provide a full review soon, but in the meantime...

Re: #12011 (comment) -- I have encountered this 64 vs 32 bit problem in the past. I got around it by using the # doctest: +ELLIPSIS trick (though I don't think it works with FLOAT_CMP, so you have to make a choice there).

Copy link
Member
@nstarman nstarman left a comment

Choose a reason for hiding this comment

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

Finished my first look. Overall this is really great! Re-request a review when you get a chance to look at some of suggestions.

Copy link
Member
@pllim pllim left a comment

Choose a reason for hiding this comment

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

Overall, nice clean-up and it is good to have more of the examples actually tested. Thank you! 👏

I left a general review but subpackage maintainers should also have a look, as there are some content changes, in addition to stylistic.

Nitpick: Inconsistent use of :class: throughout; while this does not affect the rendered output, would still be nice to be consistent.

I am also going to run the cron jobs here, as I see new links added. Want to make sure the new doctests and links don't break stuff.

For other reviewers, rendered doc can be viewed at https://astropy--12011.org.readthedocs.build/en/12011/

@pllim pllim added the Extra CI Run cron CI as part of PR label Aug 4, 2021
@pllim pllim requested review from taldcroft and mhvk August 4, 2021 20:06
@eerovaher
Copy link
Member Author

Nitpick: Inconsistent use of :class: throughout; while this does not affect the rendered output, would still be nice to be consistent.

I agree that it would be better to be more consistent with the use of :class:, but at this point ensuring that would require quite a lot of work and it wouldn't even affect the rendered HTML.

@pllim
Copy link
Member
pllim commented Aug 5, 2021

Re: :class: -- I don't mean for you to go clean up all the docs, but at least be consistent in your diff? I don't see why we need to switch between both of these in the same patch:

:class:`numpy.<func>`

`numpy.<func>`

Copy link
Member
@taldcroft taldcroft left a comment

Choose a reason for hiding this comment

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

Amazing work @eerovaher, I cannot say thank you enough!! I made a few comments and weighed in on a couple of outstanding questions. If you address those then I think this will be OK to approve and merge.

>>> dat = [[1, 2], ['hello', 'world']]
>>> qt = QTable(dat, names=['a', 'b'], units=(u.m, None))
>>> t = Table(dat, names=['a', 'b'], units=(u.m, None))
Copy link
Member

Choose a reason for hiding this comment

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

Yes, let's revert to using QTable. The big picture story is that we want to encourage users (by example and explicitly with notes) to always use QTable for tables with meaningful units. Some of the quasi-unit functionality in Column may eventually be deprecated and removed.

>>> print(obs_mean) # doctest: +FLOAT_CMP
name mag_b mag_v
---- ------------------ ------------------
M101 15.000000000000002 13.725000000000001
Copy link
Member

Choose a reason for hiding this comment

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

In this case I think that the clarity of the example in the original version is more important than having this doctested. I.e. having all those useless digits is just very distracting.

One other option is to set the column formats prior to printing.

@eerovaher
Copy link
Member Author
eerovaher commented Aug 9, 2021

I've addressed the feedback and added a few more hyperlinks.

I also decided to add code examples to the known problems described in the documentation so that if those problems are ever fixed the examples would cause the doctests to fail. There were a handful of such described issues, but I was only able to add a single new code example two new code examples because it turned out the other problems had been fixed already. See the commit messages for details.

@eerovaher
Copy link
Member Author

I was able to make Sphinx render the links to Table and Column formatting methods in the preferred way described in #12011 (comment), so that's what the last commit implements.

Copy link
Member
@nstarman nstarman left a comment

Choose a reason for hiding this comment

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

Thanks for tackling all the suggestions. In particular the example table formatting is much improved.

Copy link
Member
@pllim pllim left a comment

Choose a reason for hiding this comment

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

I have left a general review before, so I'll not review again. Final approval should come from subpackage maintainers. Thanks for your continued effort and patience!

@nstarman
Copy link
Member

Thanks again @eerovaher for the diligent follow through. As this PR is winding up, I've started resolved conversations, checking that the comments were addressed. I think there's only 1 or 2 still active!

@taldcroft
Copy link
Member

@eerovaher - this is good now and I'm planning to approve and merge. Just one last request at the end of this long road, and that is to squash the commits down to one. I think there is not much value-added in the individual commits for these doc fixes.

This commit fixes typos and formatting mistakes, adds hyperlinks,
removes obsolete sections and increases test coverage. For more details
see PR astropy#12011.
<astropy.table.Conf.replace_warnings>` in the :ref:`astropy_config`. This
controls a set of warnings that are emitted under certain circumstances when a
table column is replaced. This option must be set to a list that includes zero
or more of the following string values:
Copy link
Member Author

Choose a reason for hiding this comment

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

I've added a link to the attribute in this section too.

@eerovaher
Copy link
Member Author

I have squashed the commits and made the two changes that @nstarman requested. The cron failures are caused by apt-get install and are unrelated to the PR itself.

@taldcroft
Copy link
Member

Have you looked into the ci/circleci: image-tests-mpldev fail? Presumably unrelated?

@eerovaher
Copy link
Member Author

This is the error message: ERROR: InvocationError for command /root/project/.tox/py37-test-image-mpldev/bin/pytest --pyargs astropy /root/project/docs --mpl -P visualization --remote-data=astropy --open-files --mpl-results-path=/root/project/results -W ignore:np.asscalar (exited with code 3)
I'm not sure what it means but it looks like the error occurred before any tests could run at all.

Copy link
Member
@taldcroft taldcroft left a comment

Choose a reason for hiding this comment

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

Thanks @eerovaher !

@taldcroft taldcroft merged commit fe8b446 into astropy:main Aug 18, 2021
nstarman pushed a commit to nstarman/astropy that referenced this pull request Aug 19, 2021
This commit fixes typos and formatting mistakes, adds hyperlinks,
removes obsolete se
433
ctions and increases test coverage. For more details
see PR astropy#12011.
nstarman pushed a commit to nstarman/astropy that referenced this pull request Aug 19, 2021
This commit fixes typos and formatting mistakes, adds hyperlinks,
removes obsolete sections and increases test coverage. For more details
see PR astropy#12011.
@eerovaher eerovaher deleted the table-docs branch August 31, 2021 12:00
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.

4 participants
0