Skip to content

BUG: nested construction with timedelta #11129 #11134

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 1 commit into from
Sep 17, 2015

Conversation

chris-b1
Copy link
Contributor

Closes #11129

Per discussion in issue this adds similar hash equality to _Timedelta / datetime.timedelta
that exists for _Timestamp / datetime.datime.

I tried inlining _Timedelta._ensure_components and it actually hurt performance a bit, so I left it
as a plain def but did build a seperate _has_ns check for hashing.

Adds a little overhead to hashing:

In [1]: tds = pd.timedelta_range('1 day', periods=100000)

# PR
In [2]: %timeit [hash(td) for td in tds]
1 loops, best of 3: 810 ms per loop

# Master
In [2]: %timeit [hash(td) for td in tds]
1 loops, best of 3: 765 ms per loop

@jreback
Copy link
Contributor

jreback commented Sep 17, 2015

try making it a cpdef

@jreback
Copy link
Contributor

jreback commented Sep 17, 2015

hmm, no reason ever to do hash like that in a loop though..

@jreback jreback added Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode Dtype Conversions Unexpected or buggy dtype conversions Timedelta Timedelta data type labels Sep 17, 2015
@jreback jreback added this to the 0.17.0 milestone Sep 17, 2015
@@ -2177,6 +2180,13 @@ cdef class _Timedelta(timedelta):
"""
return timedelta(microseconds=int(self.value)/1000)

cdef inline bint _has_ns(_Timedelta td):
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

make this a method of _Timedelta.

self.value % 1000 != 0 (might be same speed)

@chris-b1
Copy link
Contributor Author

changing to a cpdef didn't seem to matter, assuming I'm profiling the right thing (I think component access would take a call to _ensure_components())?

In [2]: %timeit tds.microseconds
#cpdef
1 loops, best of 3: 776 ms per loop
#def
1 loops, best of 3: 775 ms per loop

@jreback
Copy link
Contributor

jreback commented Sep 17, 2015

lgtm. pls change _has_ns to be a method of _Timedelta

@chris-b1
Copy link
Contributor Author

@jreback made that change, Travis green.

jreback added a commit that referenced this pull request Sep 17, 2015
BUG: nested construction with timedelta #11129
@jreback jreback merged commit 6785475 into pandas-dev:master Sep 17, 2015
@jreback
Copy link
Contributor

jreback commented Sep 17, 2015

thank u sir!

@chris-b1 chris-b1 deleted the timedelta-hash branch September 17, 2015 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants