Skip to content

REF: implement shift_bday #34761

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 3 commits into from
Jun 14, 2020
Merged

REF: implement shift_bday #34761

merged 3 commits into from
Jun 14, 2020

Conversation

jbrockmendel
Copy link
Member

Avoids depending on DatetimeArray/PeriodArray methods, also avoids a couple of array allocations

In [2]: dti = pd.date_range("2016-01-01", periods=10**5, freq="S")                                                                     

In [3]: off = pd.offsets.BDay()                                                                                                        

In [4]: %timeit dti + off                                                                                                              
24.1 ms ± 202 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)  # <-- master
20.1 ms ± 664 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)  # <-- PR

@gfyoung gfyoung added Internals Related to non-user accessible pandas implementation Refactor Internal refactoring of code Datetime Datetime data dtype labels Jun 14, 2020
@jreback jreback added this to the 1.1 milestone Jun 14, 2020
@@ -3991,6 +3974,51 @@ def shift_months(const int64_t[:] dtindex, int months, object day=None):
return np.asarray(out)


cdef ndarray[int64_t] shift_bdays(const int64_t[:] i8other, int periods):
cdef:
Copy link
Contributor

Choose a reason for hiding this comment

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

can you doc-string args

if val == NPY_NAT:
result[i] = NPY_NAT
else:
# The rest of this is effectively a copy of BusinessDay.apply
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO here to consolidate?

Copy link
Member Author

Choose a reason for hiding this comment

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

not really feasible; different types.

@jreback jreback merged commit 87d8b5e into pandas-dev:master Jun 14, 2020
@jbrockmendel jbrockmendel deleted the ref-roll branch June 14, 2020 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Internals Related to non-user accessible pandas implementation Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants