-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Fixed pd.infer_freq
incompatible with Series["timestamp[s][pyarrow]"]
#58404
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,10 +33,7 @@ | |
from pandas.util._decorators import cache_readonly | ||
|
||
from pandas.core.dtypes.common import is_numeric_dtype | ||
from pandas.core.dtypes.dtypes import ( | ||
DatetimeTZDtype, | ||
PeriodDtype, | ||
) | ||
from pandas.core.dtypes.dtypes import PeriodDtype | ||
from pandas.core.dtypes.generic import ( | ||
ABCIndex, | ||
ABCSeries, | ||
|
@@ -112,20 +109,16 @@ def infer_freq( | |
>>> pd.infer_freq(idx) | ||
'D' | ||
""" | ||
from pandas.api.types import is_datetime64_any_dtype | ||
from pandas.core.api import DatetimeIndex | ||
|
||
if isinstance(index, ABCSeries): | ||
values = index._values | ||
if not ( | ||
lib.is_np_dtype(values.dtype, "mM") | ||
or isinstance(values.dtype, DatetimeTZDtype) | ||
or values.dtype == object | ||
): | ||
raise TypeError( | ||
"cannot infer freq from a non-convertible dtype " | ||
f"on a Series of {index.dtype}" | ||
) | ||
index = values | ||
if isinstance(index, ABCSeries) and not ( | ||
is_datetime64_any_dtype(index) or index.dtype == object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a bit surprised by this comment, isn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For internal usages, checking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I guess I accidentally removed checking for timedelta. Although no tests failed. I am adding some tests for timedeltas as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is another bug: when trying with the easiest workaround would be to cast to numpy, but I guess we want to avoid that and keep dtype as pyarrow inside the ops. |
||
): | ||
raise TypeError( | ||
"cannot infer freq from a non-convertible dtype " | ||
f"on a Series of {index.dtype}" | ||
) | ||
|
||
inferer: _FrequencyInferer | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.