-
-
Notifications
You must be signed in to change notification settings - Fork 314
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
Coercing DateTimeIndex fails starting with Pandera v0.13.4 #1046
Comments
@cristianmatache As #972 submitter, and in light with the text above, any idea why Index (vs Series) seems to have no 'dt' field ? |
@davidandreoletti it looks like i haven't handled that case properly, only Series' have We should add an if statement to check whether if (
hasattr(pandas_dtype, "tz")
and pandas_dtype.tz is not None
):
# localize datetime column so that it's timezone-aware
if hasattr(col, 'dt') and col.dt.tz is None: # Series
col = col.dt.tz_localize(pandas_dtype.tz, **_tz_localize_kwargs)
elif col.tz is None: # Index
col = col.tz_localize(pandas_dtype.tz, **_tz_localize_kwargs)
return col.astype(pandas_dtype) |
I can have a look at this early next week, if you need the functionality before that, please feel free to submit a PR. |
Thanks @cristianmatache for the PR #1057 ! |
Resurfacing this as the issue still seems to persist and PR #1057 remains unmerged. @cristianmatache, could you please sign your commit as explained here? |
Describe the bug
When passed the following date time index to DateTime._coerce(...)'s inline function _to_datetime
with schema instance built from
and starting with #972, Pandera fails to coerce <class 'pandas.core.indexes.datetimes.DatetimeIndex'> data_container into type datetime64[ns, UTC] due to missing
dt
called here:pandera/pandera/engines/pandas_engine.py
Line 816 in 5aa7795
Pandera/Pandas/Bug Status matrix:
Pandera 0.12.0 / Pandas 1.4.4-1.5.2 => coercion success
Pandera 0.13.4 / Pandas 1.4.4-1.5.2 => coercion failure
The difference seems to be that the coercion happened on a series on #972 while in the code sample above it is on an index.
Workaround
Use Pandera 0.12.0
Code Sample, a copy-pastable example
See above.
Expected behavior
Coercing succeeds
Desktop (please complete the following information):
Screenshots
NA
Additional context
NA
The text was updated successfully, but these errors were encountered: