Skip to content

PERF/CLN: infer Period in infer_dtype, later index inference is faster #3332

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
Apr 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def __new__(cls, data, dtype=None, copy=False, name=None):
from pandas.tseries.index import DatetimeIndex
return DatetimeIndex(subarr, copy=copy, name=name)

if lib.is_period_array(subarr):
return PeriodIndex(subarr, name=name)
elif inferred == 'period':
return PeriodIndex(subarr, name=name)

subarr = subarr.view(cls)
subarr.name = name
Expand Down
8 changes: 8 additions & 0 deletions pandas/src/inference.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def infer_dtype(object _values):
if is_timedelta_or_timedelta64_array(values):
return 'timedelta'

elif is_period(val):
if is_period_array(values):
return 'period'

for i in range(n):
val = util.get_value_1d(values, i)
if util.is_integer_object(val):
Expand Down Expand Up @@ -321,6 +325,10 @@ def is_time_array(ndarray[object] values):
return False
return True

def is_period(object o):
from pandas import Period
return isinstance(o,Period)

def is_period_array(ndarray[object] values):
cdef int i, n = len(values)
from pandas import Period
Expand Down