Skip to content

implement TimedeltaArray asm8, to_timedelta64 #23205

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

Merged
merged 8 commits into from
Oct 23, 2018

Conversation

jbrockmendel
Copy link
Member

For compat with Timedelta scalar

@pep8speaks
Copy link

Hello @jbrockmendel! Thanks for submitting the PR.

@codecov
Copy link

codecov bot commented Oct 17, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@4cac923). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #23205   +/-   ##
=========================================
  Coverage          ?   92.19%           
=========================================
  Files             ?      169           
  Lines             ?    50958           
  Branches          ?        0           
=========================================
  Hits              ?    46979           
  Misses            ?     3979           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.61% <100%> (?)
#single 42.27% <50%> (?)
Impacted Files Coverage Δ
pandas/core/arrays/timedeltas.py 94.08% <100%> (ø)

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 4cac923...a1e1127. Read the comment docs.

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Just a general comment: for Timestamp / DatetimeIndex you have the same inconsistency of to_datetime64.
Also on the Index/Array classes, you already have other ways to get the numpy array (np.array(..), although might sometimes give object dtype). Mainly wondering if we should have a more general API across the arrays to convert to certain numpy types.

--------
Timedelta.to_timedelta64
"""
return self.asi8.view('m8[ns]')
Copy link
Member

Choose a reason for hiding this comment

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

you are going a little bit in circles here, as asi8 itself is already self.values.view('i8') ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I find asi8 much more explicit than alues (BTW as I mentioned to jreback the "v" key on my keyboard is sticky; I'm going to stop copy-pasting and let you guys infer the missing letter for a while).

return self.asi8.view('m8[ns]')

@property
def asm8(self):
Copy link
Member

Choose a reason for hiding this comment

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

do we need both to_timedelta64 and asm8 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we were starting fresh I would say no, but as it is I think consistency with the scalar type is really worthwhile. (and to your point aboe DatetimeIndex should have a to_datetime64 method)

@jreback jreback added the Timedelta Timedelta data type label Oct 18, 2018
@jreback jreback added this to the 0.24.0 milestone Oct 18, 2018
@jbrockmendel
Copy link
Member Author

Updated to implement DatetimeArray.asm8, DatetimeArray.to_datetime64

@jorisvandenbossche
Copy link
Member

Thinking about this a bit more: I am -1 on adding duplicate attributes/methods just for sake of consistency with our scalar type Timestamp/Timedelta. We already have a bloated API.

Also for DatetimeIndex/TimedeltaIndex, it is not really clear to me what this is targeted use case is, as it just returns a copy of itself? (except that it returns an array instead of index? Which I also don't find clear from the name)

@jbrockmendel
Copy link
Member Author

Thinking about this a bit more: I am -1 on adding duplicate attributes/methods just for sake of consistency with our scalar type Timestamp/Timedelta. We already have a bloated API.

Would you advocate removing one/both of the attributes from the Timedelta/Timestamp scalars?

@jreback
Copy link
Contributor

jreback commented Oct 23, 2018

lgtm. waiting for CI to merge.

@jreback jreback merged commit 6e50713 into pandas-dev:master Oct 23, 2018
@jreback
Copy link
Contributor

jreback commented Oct 23, 2018

thanks!

@jbrockmendel jbrockmendel deleted the to_td64 branch October 23, 2018 02:56
jorisvandenbossche added a commit that referenced this pull request Oct 23, 2018
jorisvandenbossche added a commit to jorisvandenbossche/pandas that referenced this pull request Oct 23, 2018
@jorisvandenbossche
Copy link
Member

Sorry, Jeff, but I clearly objected this PR. Can you then at least discuss it before merging?
So I reverted the PR.

@jreback
Copy link
Contributor

jreback commented Oct 23, 2018

@jorisvandenbossche if u object then your need to actually put in a review request to do so

JustinZhengBC pushed a commit to JustinZhengBC/pandas that referenced this pull request Oct 23, 2018
tm9k1 pushed a commit to tm9k1/pandas that referenced this pull request Nov 19, 2018
tm9k1 pushed a commit to tm9k1/pandas that referenced this pull request Nov 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TimedeltaIndex should have to_timedelta64 mirroring Timedelta
4 participants