-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Allow Time input/interaction/output with Quantities (closes #751) #1431
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be other.__sub__(self) -- could make a difference if the datatype is unsigned (I know that would be bad in other ways, but why not?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdboom - no, it has to call itself: the reason we can get here is if, e.g., one does Quantity - TimeDelta. For this case, python first gives Quantity a chance, looking up its __sub__ method. It should raise NotImplemented (it doesn't yet, but it should), as it doesn't know how to add to a TimeDelta. Then, python checks whether TimeDelta has a __rsub__ method, and gives that a chance: but of course this then should use its own method, as for this case we know other.__sub__ fails.
|
@mdboom - only one of your comments had a very clear answer -- the others all bring up in one way or another a more general question I was thinking about while implementing this: to what extent should Here, a range of options are available:
Of course, these are mostly design choices and I'm not quite clear what the |
|
@mbboom, @taldcroft - I added lots of test cases and rebased. But my questions above still hold... Also, to avoid it disappearing in an outdated diff: @mboom, you asked
I'm not sure -- it seems a bit overkill, and I'm not sure how useful it is if it is not convertible (and I do not see how to convert it). |
|
Just tried and failed to understand what the test failure was for python 3.3 -- suggestions welcome... |
|
@mhvk - this and some of your other recent PRs are on my radar, but my day job is getting in the way big time. Apologies and thanks for your patience... |
|
@mdboom, @taldcroft - I noticed that the test cases I added actually hadn't made it in -- the risks of |
|
The travis build error is from the documentation, with a complaint that the right version of sphinx is not available. |
|
Ah right, I've opened a PR with a fix: #1478 |
|
@mhvk - This is really great and a very good addition to Time. Thanks for the hard work! It looks like there is still a test failure for python 3.3 that needs fixing. Otherwise what would be good is a section in the Time docs like |
|
@mhvk - you will need to rebase to get rid of the Sphinx failure. |
|
@astrofrog - OK, rebased. Still to do are @taldcroft's suggested updates to the documentation. |
|
@taldcroft - now updated the documentation. Maybe we can chat tomorrow about the more general questions I posed earlier (about where to import units, etc.) |
|
@taldcroft, @mdboom, @astrofrog - this seems quite complete; just pinging in case it was being forgotten... |
|
@mhvk - there are a couple of warnings in the docs causing the failure: I'll leave it up to @taldcroft to do a final review and merge. |
|
@astrofrog - I made a correction, but travis seems to have balked for reasons that appear to be unrelated to this. |
|
I've restarted Travis |
|
@mhvk - I was (and am) waiting on a clean Travis doc build before merge, otherwise this looks fine (no, great!). The doc build error is occurring in astropy.time code so it may indeed be related. Are you able to build the docs locally? |
|
@taldcroft - I finally moved over to python3 and thus could check the build failure -- it was an Now if only travis would start, we'd know if this is OK (@astrofrog?)... |
|
@taldcroft - tests are passing, feel free to merge. |
Allow Time input/interaction/output with Quantities (closes #751)
In #751, it was argued that
TimeandQuantityshould interact properly, with @taldcroft giving a list of expected behavour:TimeDeltato different units withto().QuantityandTimeDeltaorTime(regardless of argument order) should give aTimeDelta.TimeDeltaby a Quantity should result in a Quantity.Furthermore, currently, input of Quantities is ignored -- just the value is taken (
TimeDelta(10.*u.s, format='jd')silently gives a 10-day time difference; same forTime).This PR addresses the initialisation of both
TimeandTimeDeltaand implements most of the above -- the exception is thatQuantity <OP> TimeDeltadoes not work, asQuantity(andndarray) fail to returnNotImplementedon trying to add aTimeorTimeDelta[EDIT: now raised an issue, #1455])Suggestions most welcome; if it is agreed this is in the right direction, I can add tests/documentation (PR's to my branch more than welcome...).