Skip to content

Fix units to be able to compose from equivalent units that have prefixes - #6957

Merged
mhvk merged 7 commits into
astropy:masterfrom
fastakash:bugfix-for-issue-4104
Jan 8, 2018
Merged

mhvk merged 7 commits into
astropy:masterfrom
fastakash:bugfix-for-issue-4104

Conversation

@fastakash

@fastakash fastakash commented Dec 9, 2017 •

Copy link
Copy Markdown
Contributor

Fix #4104.

Made changes as suggested and added some tests also. My first commit to astropy and github! Took me a long time to figure out all the steps.

@astropy-bot

astropy-bot Bot commented Dec 9, 2017 •

Copy link
Copy Markdown

Hi there @fastakash 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labeled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃.

Everything looks good from my point of view! 👍

If there are any issues with this message, please report them here.

@bsipocz bsipocz added the units label Dec 9, 2017
fastakash added a commit to fastakash/astropy that referenced this pull request Dec 9, 2017
@fastakash

Copy link
Copy Markdown
Contributor Author

Hi @bsipocz can you please add the label work-in-progress? I initially thought my work was fine but now see that a failing unit-test is because of the change I made. I will investigate further.

Sorry for the PR being premature

@fastakash

Copy link
Copy Markdown
Contributor Author

The label "work in progress" may now be removed. Hoping for a review/comment next!

@pllim
pllim requested a review from mhvk December 16, 2017 16:52
@bsipocz bsipocz changed the title Bugfix for issue #4104 Fix units to be able to compose from equivalent units that have prefixes Dec 18, 2017
@bsipocz

bsipocz commented Dec 18, 2017

Copy link
Copy Markdown
Member

@fastakash - I've changed the title of your PR to be more informative about its content (as probably none of us knows the issues by their number).

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@fastakash - thanks very much for addressing this long-standing issue! Your solution is good and my comments are about details of the tests, and ensuring the new behaviour is documented.

Comment thread astropy/units/tests/test_units.py Outdated
(u.AA * u.erg) ** 9


def test_compose():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The tests seem somewhat scattered already, but maybe try to keep this closer to another similar set of tests; e.g., just before test_compose_issue_579 and then name your functiontest_compose_prefix_unit.

Comment thread astropy/units/core.py
# if the specified units list explicitly contains prefix units,
# include_prefix_units should be turned on. Ex: units=[u.kpc]
if include_prefix_units is None:
include_prefix_units = isinstance(units, (list, tuple))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should be sure to also document this, i.e., in the description of include_prefix_units. Maybe just

Default is `True` if a sequence is passed in to ``units``, `False` otherwise.

Comment thread astropy/units/tests/test_units.py Outdated


def test_compose():
x = u.m.compose(units=(u.m))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is sufficiently tested elsewhere, so I would instead replace it with something else that uses a tuple (but then add the trailing ,!). Also, maybe make the test a bit more realistic by adding multiple possible units. E.g.,

x = (u.km/u.s).compose(units=(u.pc, u.Myr))
assert x[0].bases == [u.pc, u.Myr]
assert_allclose(x[0].scale, 1.0227121650537077)

Comment thread astropy/units/tests/test_units.py Outdated
x = u.m.compose(units=[u.km])
assert x[0].bases[0] is u.km
assert x[0].scale == 0.001

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Of course, also important to test whether things fail when include_prefix_units=False:

with raises(u.UnitsError):
    (u.km/u.s).compose(units=(u.pc, u.Myr), include_prefix_units=False)

Comment thread CHANGES.rst Outdated
^^^^^^^^^^^^^

- When a prefix unit is specified, include_prefix_units should be automatic
[#4104, #6957]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We usually just specify the PR, not the original issue.

@fastakash

Copy link
Copy Markdown
Contributor Author

@mhvk Thanks for patiently explaining everything to me! I hope I addressed all your feedback. I will be more careful with reviewing all the existing unittests in the future. I know this was a small task that you could have probably finished yourself in minutes! I hope to pick up more and bigger tasks, especially in the summer.

@fastakash

Copy link
Copy Markdown
Contributor Author

Hi @mhvk Thanks again for your help. Do you think my updates are ok? If you are busy, please ignore this message! I will start looking at other issues.. thanks

Comment thread astropy/units/core.py Outdated
include_prefix_units : bool, optional
Default is `True` if a sequence is passed in to ``units``,
`False` otherwise.
When `True`, include prefixed units in the result.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

THis got a bit mangled. Could you change it to

When `True`, include prefixed units in the result.
Default is `True` if a sequence is passed in to ``units``,
`False` otherwise.

@mhvk

mhvk commented Jan 8, 2018

Copy link
Copy Markdown
Contributor

@fastakash - apart from the very minor comment about the docstring, this all looks good. If you change that one, add [ci skip] to your commit message, since it is not necessary to run the tests again.

fastakash and others added 7 commits January 8, 2018 15:44
@mhvk
mhvk force-pushed the bugfix-for-issue-4104 branch from 65128d6 to 2a24ec2 Compare January 8, 2018 20:47
@mhvk mhvk added this to the v3.1 milestone Jan 8, 2018
@mhvk

mhvk commented Jan 8, 2018

Copy link
Copy Markdown
Contributor

@fastakash - I realized the changelog was for 3.0, but this will have to be in 3.1, so I went ahead and moved it (rebasing to be sure I picked up the new changelong entries). Otherwise, it all looks good, so I'll merge. Thanks!

@mhvk
mhvk merged commit 88a5f14 into astropy:master Jan 8, 2018
@fastakash
fastakash deleted the bugfix-for-issue-4104 branch January 8, 2018 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants