Skip to content

Can't convert Categorical to 'datetime64[ns, MET]', but can do it with Series #28448

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

Closed
MarcoGorelli opened this issue Sep 14, 2019 · 4 comments · Fixed by #29269
Closed

Can't convert Categorical to 'datetime64[ns, MET]', but can do it with Series #28448

MarcoGorelli opened this issue Sep 14, 2019 · 4 comments · Fixed by #29269
Labels
Categorical Categorical Data Type Timezones Timezone data dtype
Milestone

Comments

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Sep 14, 2019

Code Sample, a copy-pastable example if possible

from pandas import Categorical

Categorical(['2015-01-01']).astype('datetime64[ns]')  # works
Categorical(['2015-01-01']).astype('datetime64[ns, MET]')  # fails

This is because the astype method returns

       np.array(self, dtype=dtype, copy=copy)

, and numpy arrays don't handle this dtype.

Is this expected behaviour?

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit : None python : 3.7.3.final.0 python-bits : 64 OS : Linux OS-release : 4.15.0-60-generic machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_GB.UTF-8 LOCALE : en_GB.UTF-8

pandas : 0.25.1
numpy : 1.16.4
pytz : 2019.2
dateutil : 2.8.0
pip : 19.1.1
setuptools : 41.0.1
Cython : None
pytest : 5.0.1
hypothesis : None
sphinx : 2.2.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.8.0
pandas_datareader: None
bs4 : 4.8.0
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.1
numexpr : 2.7.0
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.13.0
pytables : None
s3fs : None
scipy : 1.2.1
sqlalchemy : None
tables : 3.5.2
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None

@WillAyd
Copy link
Member

WillAyd commented Sep 16, 2019

I think this should be consistent so probably OK to support. If you have a PR you'd like to submit would certainly welcome one

@MarcoGorelli
Copy link
Member Author

MarcoGorelli commented Oct 8, 2019

Fixed by #28762

@jreback
Copy link
Contributor

jreback commented Oct 8, 2019

hmm do we have a test for this?

@MarcoGorelli
Copy link
Member Author

@jreback sorry for the delay - I've just reopened this and added a test

@jreback jreback added this to the 1.0 milestone Oct 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants