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
BUG: to_datetime inconsistent output container type #28629
Comments
I tried like this @@ -215,7 +215,7 @@ def _convert_and_box_cache(
"""
from pandas import Series
- result = Series(arg).map(cache_array)
+ result = Series(arg).map(cache_array).astype('datetime64')
if box:
return _box_as_indexlike(result, utc=None, name=name)
return result.values and I'm on the testing 25% |
the branch of those two cases is pandas/pandas/core/tools/datetimes.py Lines 161 to 188 in 53ad101
|
nevermind! it spews out a lot of errors |
You hit this condition: pandas/pandas/core/tools/datetimes.py Line 105 in 171c716
In addition to |
I just hit a variant of the same something's-weird-with-the-cache logic bug. The real-world case was a lot less obviously silly than this, but:
where a total length of 50 works fine. As expected, setting cache=False makes things work again. |
Any thoughts on which is correct behavior here: Categorical -> Categorical (maintain container type) or Categorical -> DatetimeIndex? |
I would say returning |
Code Sample, a copy-pastable example if possible
Problem description
The output container type is inconsistent for
pd.to_datetime
and flips once the series is above 50 rows. This is an issue since theCategoricalIndex
class does not support DateTime-like operations (tz_localize, stftime, etc.).Since the behaviour switches between differently sized Series objects this is particularly troublesome since code behaves quite different depending on the amount of data we feed it (e.g. unit test vs. production).
Expected Output
Consistent container type.
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.6.6.final.0
python-bits : 64
OS : Linux
OS-release : 4.9.184-linuxkit
machine : x86_64
processor :
byteorder : little
LC_ALL : C.UTF-8
LANG : C.UTF-8
LOCALE : en_US.UTF-8
pandas : 0.25.1
numpy : 1.17.0
pytz : 2019.2
dateutil : 2.8.0
pip : 19.2.2
setuptools : 39.1.0
Cython : None
pytest : 5.1.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.0.5
lxml.etree : 4.4.1
html5lib : None
pymysql : None
psycopg2 : 2.8.3 (dt dec pq3 ext lo64)
jinja2 : 2.10.1
IPython : 7.7.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.4.1
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 2.5.4
pandas_gbq : None
pyarrow : 0.13.0
pytables : None
s3fs : None
scipy : None
sqlalchemy : 1.3.7
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : 1.0.5
The text was updated successfully, but these errors were encountered: