-
-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
np.datetime64 values cast to datetime.date iff dtype == M8 #6529
Comments
The problem is that some people actually want to keep an actual note that series1.dtype is Their is no way to 'tell' what should be done here. IMHO we should convert these, and we could, but that would break backward usage. thoughts? |
The issue isn't keeping As for backward compatibility, I picked this up from a breakage in our unittests - It looks like it is a regression between 13.0 and 13.1, though 12.0 seems to have the most consistent behaviour as it doesn't change the dtype of the array at all - but that could equally be a np17 vs np18 issue. pandas 0.12.0 >>> import numpy as np
>>> import pandas as pd
>>> pd.__version__
'0.12.0'
>>> dates = pd.date_range('01-Jan-2015', '01-Dec-2015', freq='M')
>>> values1 = dates.view(np.ndarray).astype('M8[D]')
>>> series1 = pd.TimeSeries(values1, dates)
>>> series1
2015-01-31 2015-01-31 00:00:00
2015-02-28 2015-02-28 00:00:00
2015-03-31 2015-03-31 00:00:00
2015-04-30 2015-04-30 00:00:00
2015-05-31 2015-05-31 00:00:00
2015-06-30 2015-06-30 00:00:00
2015-07-31 2015-07-31 00:00:00
2015-08-31 2015-08-31 00:00:00
2015-09-30 2015-09-30 00:00:00
2015-10-31 2015-10-31 00:00:00
2015-11-30 2015-11-30 00:00:00
Freq: M, dtype: datetime64[D]
>>> pandas 0.13.0 >>> import numpy as np
>>> import pandas as pd
>>> pd.__version__
'0.13.0'
>>> dates = pd.date_range('01-Jan-2015', '01-Dec-2015', freq='M')
>>> values1 = dates.view(np.ndarray).astype('M8[D]')
>>> series1 = pd.TimeSeries(values1, dates)
>>> series1
2015-01-31 2015-01-31 00:00:00
2015-02-28 2015-02-28 00:00:00
2015-03-31 2015-03-31 00:00:00
2015-04-30 2015-04-30 00:00:00
2015-05-31 2015-05-31 00:00:00
2015-06-30 2015-06-30 00:00:00
2015-07-31 2015-07-31 00:00:00
2015-08-31 2015-08-31 00:00:00
2015-09-30 2015-09-30 00:00:00
2015-10-31 2015-10-31 00:00:00
2015-11-30 2015-11-30 00:00:00
Freq: M, dtype: datetime64[ns]
>>> pandas 0.13.1 >>> import numpy as np
>>> import pandas as pd
>>> pd.__version__
'0.13.1'
>>> dates = pd.date_range('01-Jan-2015', '01-Dec-2015', freq='M')
>>> values1 = dates.view(np.ndarray).astype('M8[D]')
>>> series1 = pd.TimeSeries(values1, dates)
>>> series1
2015-01-31 2015-01-31
2015-02-28 2015-02-28
2015-03-31 2015-03-31
2015-04-30 2015-04-30
2015-05-31 2015-05-31
2015-06-30 2015-06-30
2015-07-31 2015-07-31
2015-08-31 2015-08-31
2015-09-30 2015-09-30
2015-10-31 2015-10-31
2015-11-30 2015-11-30
Freq: M, dtype: object
>>> |
what numpy are these under? 1.7.1/2? 1.8? 0.12.0 is wrong; no numpy datetime dtypes can live except for I can prob put back to 0.13.0 which seems to make the most sense (if you are actually passing |
Agreed on the fact that def test_datetime64_values_arent_cast():
dates = pd.date_range('01-Jan-2015', '01-Dec-2015', freq='M').view(np.ndarray).astype('M8[D]')
series = pd.Series(dates)
assert np.all(series.values == dates) NB: I'm using anaconda so pandas 0.12.0 was tested against numpy 1.7.1 and 0.13+ against numpy 1.8 |
ok...#6530 should bring this back in line! thanks for the report! |
Thanks for the super quick response! |
This seems a little inconsistent to me. IMHO, it would be good to be able to rely on the the fact that if you specify a numpy array of any datetime64 type the result will still be a datetime64 type and not cast to a different type dependant on the exact dtype passed in.
The text was updated successfully, but these errors were encountered: