Repository navigation
Refactor Time and TimeDelta to inherit from common TimeBase class - #10656
Conversation
|
@mhvk - check out e8af382, which (I think) solves the whole subclass problem and would fix #10654. I don't have time right now to write the tests, but basically I got expected results with: Note that in new and init one now has hardwired references to I can put this change in a separate PR if you prefer. |
|
Also note that last commit is a bit of a WIP, there are docstring updates and other possible issues which I'll fix. |
|
This is failing on one TimeSeries test, will check. |
mhvk
left a comment
There was a problem hiding this comment.
@taldcroft - this is fantastic! And I think some kudos are due for writing things such that this refactor causes so little problems!!
In-line a comment about SCALES and FORMATS which should also be moved. Similarly, _set_scale, __add__ and __sub__ should move to Time - heck, it is probably easier to just make a quick PR to your PR.... forthcoming!
| raise TypeError("Cannot specify both 'time' and 'time_start'") | ||
|
|
||
| if time is not None and not isinstance(time, Time): | ||
| if time is not None and not isinstance(time, (Time, TimeDelta)): |
There was a problem hiding this comment.
Would it make sense to just import TimeBase and check for that?
There was a problem hiding this comment.
I thought about this, but in the end I think that the code is more readable and explicit this way, as in it tells the non-expert reader immediately that the results apply to both absolute and delta times.
It's an arbitrary line, but I thought that code inside of the time subpackage should use TimeBase (internal) while the rest would be explicit. I guess there is some philosophy here -- if we or someone else adds a new subclass of TimeBase, do we want that to be in or out from consideration? One can make valid arguments both ways.
There was a problem hiding this comment.
@taldcroft - indeed, and the advantage of Time, TimeDelta was that both were imported already. Note that I changed it to TimeBase in the later commit, but that was really because I thought that might be the reason for the doctest failure (which was instead that the same change had to be made in binned.py).
|
Hello @taldcroft 👋! It looks like you've made some changes in your pull request, so I've checked the code again for style. There are no PEP8 style issues with this pull request - thanks! 🎉 Comment last updated at 2020-10-03 10:38:06 UTC |
|
@taldcroft - I pushed directly to your branch some changes (in separate commits, just in case you'd prefer to do things differently); I also amended your I think there is a bit more refactoring that could be done, given the code now in TimeBase that is looking for attributes like |
|
@mhvk - thanks for pushing forward with a bunch more changes. Alas I had made most of those changes already locally and was doing the last bit of tidy / double-checking but got stopped before I could push. I'm pretty sure the two versions of changes will be unreconcilable by automated means, but I'll have a look manually. One thing I did was look for all instances of |
|
Reminder to open an issue about testing in TimeSeries @astrofrog. There were a couple of failures along the way that only showed up in the doc testing. IIRC the first was about initializing a TimeSeries with a TimeDelta. |
|
@taldcroft - do feel free to just remove my commits! |
|
RTD fail seems unrelated: |
|
No, it is indeed not related. See #10668 |
- Initial refactor and one change with tests passing - Move Time-only methods into Time class - Export TimeBase and fix to_pandas() issue - Update changelog - Allow Time/TimeDelta to init from any Time/TimeDelta subclass - Fix issue initializing w/ TimeDelta in TimeSeries - Move _make_value_equivalent to be Time method
|
@mhvk - AFAIK all your comments have been addressed. Also from what I can see this entirely fixes #10654 so I updated the description accordingly. |
mhvk
left a comment
There was a problem hiding this comment.
@taldcroft - this looks very good indeed! I feel a bit bad about the coverage misses, but all were there before and are of the "obviously correct code" type, so might as well leave that for another time, when we just aim go get coverage of time up to 100%. So, merging!
Description
This pull request is to address a longstanding issue that
TimeDeltainherited fromTimebut many of the methods (e.g.light_travel_time()were really not applicable. Instead now there is a base classTimeBasethat has the common methods and each independently inherits fromTimeBase.After this refactor there were only two problems that showed up in the entire astropy code base, both related to assuming
Timeas the base class. In one caseTimeBase.insert()this was fixed usingself.__class__and in the otherTable.to_pandas()usingTimeBase. There were no other code changes apart from moving methods around intact.Fixes #6828
Fixes #10654.