You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
to_datetime raises a TypeError: Argument 'date_string' has incorrect type (expected str, got numpy.str_) when the arg is a list-like of numpy.str_ objects, but not when the arg is a single numpy.str_ object.
Expected Output
I expect that it works with numpy.str_ like it does with str. assert (pd.to_datetime(s) == pd.to_datetime(s.astype(str))).all()
Or at least to be consistent between pd.to_datetime(s) and pd.to_datetime(s.iloc[0])
Output of pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.0-40-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
The text was updated successfully, but these errors were encountered:
arnau126
changed the title
[to_datetime] TypeError: Expected unicode, got numpy.str_
[to_datetime] TypeError: Argument 'date_string' has incorrect type (expected str, got numpy.str_)
Feb 26, 2020
Looks like there are a couple of places in _libs.tslibs.parsing where things are typed as str so choking on np.str_. This has been a PITA elsewhere because isinstance(value, str) evalutes to True in python-space.
3 options come to mind:
make a fused type for str +np.str_ and update types in parsing.pyx
add a check in parse_datetime_string for np.str_ and cast if necessary
try to get numpy/cython to handle this upstream
If you'd like to try either of the first two, a PR would be welcome.
I had the same issue (with a column ['CollectionTime'] in dataframe collection_ct_data_v2), but solved via:
`
conv_to_string = [str(x) for x in collection_ct_data_V2['CollectionTime']]
collection_ct_data_V2['CollectionTime'] = conv_to_string
collection_ct_data_V2['CollectionTime'] = pd.to_datetime(collection_ct_data_V2['CollectionTime'])
`
This results in converted data from type numpy.str_ to string to DateTime, as desired.
Code Sample
Traceback:
Problem description
to_datetime
raises aTypeError: Argument 'date_string' has incorrect type (expected str, got numpy.str_)
when the arg is a list-like of numpy.str_ objects, but not when the arg is a single numpy.str_ object.Expected Output
I expect that it works with numpy.str_ like it does with str.
assert (pd.to_datetime(s) == pd.to_datetime(s.astype(str))).all()
Or at least to be consistent between
pd.to_datetime(s)
andpd.to_datetime(s.iloc[0])
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.0-40-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.1
numpy : 1.18.1
pytz : 2019.2
dateutil : 2.8.0
pip : 20.0.2
setuptools : 45.0.0
Cython : 0.29.13
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.4.2
html5lib : None
pymysql : 0.9.3
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.2.0
pandas_datareader: None
bs4 : 4.8.2
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.4.2
matplotlib : 3.0.2
numexpr : None
odfpy : None
openpyxl : 2.6.2
pandas_gbq : None
pyarrow : 0.13.0
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.2.17
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: