-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: to_datetime with errors coerce throws InvalidOperation decimal.DivisionImpossible #51084
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
Comments
thanks @gkep for the report this comes from dateutil: In [4]: from dateutil.parser import parse as du_parse
In [5]: du_parse('87156549591102612381000001219H5')
---------------------------------------------------------------------------
InvalidOperation Traceback (most recent call last)
Cell In[5], line 1
----> 1 du_parse('87156549591102612381000001219H5')
File ~/pandas-dev/.311venv/lib/python3.11/site-packages/dateutil/parser/_parser.py:1368, in parse(timestr, parserinfo, **kwargs)
1366 return parser(parserinfo).parse(timestr, **kwargs)
1367 else:
-> 1368 return DEFAULTPARSER.parse(timestr, **kwargs)
File ~/pandas-dev/.311venv/lib/python3.11/site-packages/dateutil/parser/_parser.py:640, in parser.parse(self, timestr, default, ignoretz, tzinfos, **kwargs)
636 if default is None:
637 default = datetime.datetime.now().replace(hour=0, minute=0,
638 second=0, microsecond=0)
--> 640 res, skipped_tokens = self._parse(timestr, **kwargs)
642 if res is None:
643 raise ParserError("Unknown string format: %s", timestr)
File ~/pandas-dev/.311venv/lib/python3.11/site-packages/dateutil/parser/_parser.py:740, in parser._parse(self, timestr, dayfirst, yearfirst, fuzzy, fuzzy_with_tokens)
736 value = None
738 if value is not None:
739 # Numeric token
--> 740 i = self._parse_numeric_token(l, i, info, ymd, res, fuzzy)
742 # Check weekday
743 elif info.weekday(l[i]) is not None:
File ~/pandas-dev/.311venv/lib/python3.11/site-packages/dateutil/parser/_parser.py:936, in parser._parse_numeric_token(self, tokens, idx, info, ymd, res, fuzzy)
932 (idx, hms) = self._parse_hms(idx, tokens, info, hms_idx)
933 if hms is not None:
934 # TODO: checking that hour/minute/second are not
935 # already set?
--> 936 self._assign_hms(res, value_repr, hms)
938 elif idx + 2 < len_l and tokens[idx + 1] == ':':
939 # HH:MM[:SS[.ss]]
940 res.hour = int(value)
File ~/pandas-dev/.311venv/lib/python3.11/site-packages/dateutil/parser/_parser.py:1047, in parser._assign_hms(self, res, value_repr, hms)
1044 if hms == 0:
1045 # Hour
1046 res.hour = int(value)
-> 1047 if value % 1:
1048 res.minute = int(60*(value % 1))
1050 elif hms == 1:
InvalidOperation: [<class 'decimal.DivisionImpossible'>] I'd suggest reporting there As for what to do on the pandas side, this should probably be caught, we just need to add this exception to pandas/pandas/_libs/tslibs/parsing.pyx Lines 892 to 896 in 5645847
, and add a test case for this in pandas/pandas/tests/tslibs/test_parsing.py Lines 238 to 254 in a23f101
Interested in submitting a PR? |
take |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
Function should return NaT in case of problem, not exception decimal.DivisionImpossible:
InvalidOperation: [<class 'decimal.DivisionImpossible'>]
Problem present also in former versions of pandas.
Expected Behavior
x = pd.NaT
Installed Versions
INSTALLED VERSIONS
commit : 87cfe4e
python : 3.10.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 154 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en
LOCALE : English_United States.1252
pandas : 1.5.0
numpy : 1.23.1
pytz : 2022.1
dateutil : 2.8.2
setuptools : 57.0.0
pip : 22.2.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.31.1
pandas_datareader: None
bs4 : None
bottleneck : 1.3.5
brotli :
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.3
numba : None
numexpr : 2.8.3
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None
The text was updated successfully, but these errors were encountered: