Skip to content

Add a to_value method to TimeDelta. - #8762

Merged
taldcroft merged 2 commits into
astropy:masterfrom
mhvk:timedelta-tovalue
May 28, 2019
Merged

taldcroft merged 2 commits into
astropy:masterfrom
mhvk:timedelta-tovalue

Conversation

@mhvk

@mhvk mhvk commented May 26, 2019

Copy link
Copy Markdown
Contributor

Makes using TimeDelta easier in places where a Quantity with units of time could be used. Does raise a more general question of how far one should extend this, and whether one should do the same for Column. But seems good in itself and would have been done at the time if Quantity had had the to_value method already.

fixes #8732

@mhvk mhvk added this to the v4.0 milestone May 26, 2019
@mhvk
mhvk requested a review from taldcroft May 26, 2019 14:40
@mhvk mhvk mentioned this pull request May 26, 2019
@codecov

codecov Bot commented May 26, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #8762 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8762      +/-   ##
==========================================
+ Coverage   86.96%   86.96%   +<.01%     
==========================================
  Files         400      400              
  Lines       59448    59450       +2     
  Branches     1100     1100              
==========================================
+ Hits        51697    51700       +3     
+ Misses       7110     7109       -1     
  Partials      641      641
Impacted Files Coverage Δ
astropy/time/core.py 94.97% <100%> (+0.01%) ⬆️
astropy/samp/hub.py 77.52% <0%> (+0.13%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 660d73b...c6d9143. Read the comment docs.

Comment thread astropy/time/core.py Outdated
return u.Quantity(self._time.jd1 + self._time.jd2,
u.day).to(*args, **kwargs)

def to_value(self, *args, **kwargs):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In general I prefer to have the actual function signature here instead of just delegating to whatever Quantity.to_value() takes. While the current approach makes this method more future-proof for Quantity.to_value API changes (probably not likely), it makes it more opaque for the user and typing dt.to_value? will give no useful help.

At the very least, need a docstring that provides information that this is calling Quantity.to_value, but preferably also shows the unit and equivalencies parameters. BTW, are there any equivalencies relevant for time delta units?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just copied from .to above, but I agree with your sentiment and will update it. (And, no, don't think there are astropy-defined equivalencies that are relevant, but of course a user might put in anything...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Of the top of my head, I can think of time / frequency equivalency. Transforming a timedelta into a frequency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@taldcroft - I now updated the TimeDelta.to_value and .to methods with proper docstrings.

@astropy astropy deleted a comment from codecov Bot May 27, 2019
@taldcroft
taldcroft merged commit 283d253 into astropy:master May 28, 2019
@mhvk
mhvk deleted the timedelta-tovalue branch May 28, 2019 19:05
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.

Add to_value for TimeDelta

3 participants