-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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: pd.to_datetime() raises InvalidIndexError with Null-like arguments #35888
Comments
I don't know if it's helpful but I also found the same / similar error today with None and to_datetime. If you are unable to replicate it, I can probably reduce the complexity of mine down (c. 58,000 rows, mixed None with dates). From my workaround attempts, I found that I can use '' instead of None to get my desired outcome NaT. If memory serves me right, I couldn't do this previously. So amending the example above, this provides 4000 NaTs
|
I think the root problem is something like this: We try to get the unique dates and then pass it to an index. In [10]: pd.unique(arg)
Out[10]: array([NaT, None], dtype=object)
In [11]: pd.Index(arg)
Out[11]: DatetimeIndex(['NaT', 'NaT'], dtype='datetime64[ns]', freq=None) But Index infers datetime dtype and converts None to NaT. So we need to somewhere standardize the NA values. I'm not sure exactly where that should be done though. We'd welcome more investigation! |
It appears this works on master now. Could use a test
|
My first time contributing - but the PR above should hopefully be a sufficient test. Not sure these tests require an addition to whatsnew? |
take |
Can I work on this? |
Sounds good - I didn't get a chance to work on it after my initial attempt, but my PR (#43006) should have the necessary changes already there, if you can get them working with automated tests, then it should be good to go 🤞🏻 . |
hey @ryangilmour, Greetings. Could you please let me know if you are still working on this or do you need any help. |
Hi @ashaypatil12 - I'm not currently working on this. If you want to make some progress on this feel free to take a look at the PR (#43006) and see if you can get that over the line.
|
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Problem description
pd.to_datetime()
crash if the input contains a mix ofNaT
andNone
with apandas.errors.InvalidIndexError: Reindexing only valid with uniquely valued Index objects
exception.This issue is similar to #22305 which was fixed a while ago. It only occurs if the input is large enough to force the caching mechanism.
Expected Output
No crash
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : f2ca0a2
python : 3.8.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.7.15-200.fc32.x86_64
Version : #1 SMP Tue Aug 11 16:36:14 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.1.1
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.1.3
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : 0.10.0
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.19
tables : None
tabulate : 0.8.7
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: