Skip to content

PERF: Using _Period for optimization #32973

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 10 commits into from
Mar 30, 2020
4 changes: 1 addition & 3 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ cnp.import_array()

cimport pandas._libs.util as util

from pandas._libs.tslibs import Period
from pandas._libs.tslibs.nattype cimport c_NaT as NaT
from pandas._libs.tslibs.c_timestamp cimport _Timestamp

Expand Down Expand Up @@ -468,9 +467,8 @@ cdef class PeriodEngine(Int64Engine):
cdef int64_t _unbox_scalar(self, scalar) except? -1:
if scalar is NaT:
return scalar.value
if isinstance(scalar, Period):
if isinstance(scalar, periodlib._Period):
Copy link
Member

Choose a reason for hiding this comment

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

you would need to cimport _Period to get the performance improvement

Copy link
Member Author

Choose a reason for hiding this comment

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

Just so I don't do anything stupid, I need to create the file period.pxd at pandas/_libs/tslibs/, correct?

Copy link
Member

Choose a reason for hiding this comment

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

yep

# NB: we assume that we have the correct freq here.
# TODO: potential optimize by checking for _Period?
return scalar.ordinal
raise TypeError(scalar)

Expand Down