Skip to content

Conversation

@mhvk
Copy link
Contributor

@mhvk mhvk commented Jan 5, 2021

This is really a spin-off from trying to get a general Masked class to work in #11127, where I wanted to ensuring that Quantity(masked, unit) gave a MaskedQuantity. But the changes I made suggested Quantity(distribution, unit) should also give a QuantityDistribution - which indeed worked! I split the required changes out of #11127, since it is likely much easier to review here (and being able to do distribution * unit is nice!).

@mhvk mhvk added this to the v4.3 milestone Jan 5, 2021
@mhvk mhvk requested review from astrofrog and eteq January 5, 2021 00:50
@mhvk mhvk force-pushed the uncertainty-initialize-as-quantity branch from 1660f07 to 2a64d5a Compare January 5, 2021 20:24
@mhvk mhvk force-pushed the uncertainty-initialize-as-quantity branch from 2a64d5a to ff1c0b7 Compare January 23, 2021 19:43
@mhvk
Copy link
Contributor Author

mhvk commented Jan 23, 2021

@eteq, @astrofrog - would one of you have time to review this (or suggest someone else)? I'd like to try to get the Masked PR in a state where it touches as little else as possible, so that it is easier to review... And the suggestion here seems good on its own.

@mhvk mhvk force-pushed the uncertainty-initialize-as-quantity branch from ff1c0b7 to 1c17aa5 Compare March 15, 2021 17:12
@mhvk
Copy link
Contributor Author

mhvk commented Mar 15, 2021

@eteq, @astrofrog - Gentle ping - quite simple PR and review would be nice...

Copy link
Member

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

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

I'll defer to @eteq for a proper review, but reading over the docs I realized we never actually spell out what QuantityDistribution is, do we?

@mhvk
Copy link
Contributor Author

mhvk commented Apr 12, 2021

@eteq - a promised ping - would be good to have this reviewed. I just rebased to use the new changelog fragment format.

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.

Nifty 👍

return super().view(dtype)
else:
result = self.distribution.view(dtype)
return Distribution(result)
Copy link
Member

@nstarman nstarman Apr 12, 2021

Choose a reason for hiding this comment

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

Nitpick and feel free to ignore. I'm just thinking of McCabe complexity. I endeavor to structure my personal code to minimize the complexity score and reducing the number of return statements is an easy couple points. I should never have turned on that checker! 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Numpy's strange choice to allow one to omit dtype and just pass in a class remains a bit annoying... I've made it slightly simpler (and found a bug on the way, so good!).

@mhvk mhvk force-pushed the uncertainty-initialize-as-quantity branch from f0372fe to 9e8c558 Compare April 13, 2021 00:26
@nstarman nstarman mentioned this pull request Apr 13, 2021
Copy link
Member

@eteq eteq left a comment

Choose a reason for hiding this comment

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

LGTM broad-brush! I have a few minor inline comments, but nothing major!

I also noticed @astrofrog's #11210 (review) - @astrofrog, were you thinking @mhvk should do that in this PR, or that we should do that separately?

Comment on lines 435 to 448
with pytest.raises(ValueError, match='just a new dtype'):
ad.view(np.dtype('f8'))
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 confusing to me. Is it that this works for a regular Angle but not one that uses Distribution? Or it doesn't work for any angle? If it's the former I think it's probably a bug (which we can fix later to not hold up this PR, but should make an issue and add a comment here) whereas if it's the latter this should probably go in the regular Angle tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, it works for Angle but cannot very easily work for any Distribution (since it has a structured dtype) - also just don't quite know what to do with things that change the number of elements (say, .view('f4')) - in practice, this basically never happens...

Anyway, I'll add a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now added a comment and restructured the .view code as well.

@astrofrog
Copy link
Member

Follow up :)

mhvk added 4 commits April 13, 2021 14:38
Also ensure that subclasses passes, independent of their order.
This allows Quantity to initialize from Distribution instances,
ensuring that will return a QuantityDistribution.
@mhvk mhvk force-pushed the uncertainty-initialize-as-quantity branch from f33ea07 to 48e6caf Compare April 13, 2021 18:38
@mhvk mhvk merged commit d3c8efb into astropy:main Apr 13, 2021
@mhvk mhvk deleted the uncertainty-initialize-as-quantity branch April 13, 2021 19:52
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