-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: to_datetime with ordinals and no unit #15836
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
I do almost exactly that (but only if
so +1 from me to require a |
Hi, i'm working on it and have few questions. In [3]: pd.to_datetime(True, unit='ms')
Out[3]: Timestamp('1970-01-01 00:00:00.001000')
In [4]: pd.to_datetime(False, unit='ms')
Out[4]: Timestamp('1970-01-01 00:00:00') Does somebody confirms it ? |
Numbers than don't fit into pd.to_datetime([np.iinfo('i8').max + 1])
OverflowError: int too big to convert And I agree that's a bug - the no unit case seem to be caught ok. pd.to_datetime(True)
TypeError: <class 'bool'> is not convertible to datetime |
Okay, thanks. The bug comes from My actual check: if arg is None:
return None
elif isinstance(arg, (bool,)):
raise TypeError("{0} is not convertible to datetime"
.format(type(arg)))
elif isinstance(arg, (int, float)) and unit is None:
raise ValueError("a unit is required in case of numerical arg") Do I keep this behaviour or skip the bool case and raise the same numerical error ? |
I'd suggest opening a PR with your changes, even if work-in-progress, that will be easier to review. I'm not sure I completely understand your question, but with
|
this would raise, because you haven't specified a The check for unit needs to done before any conversions. Its kind of like the |
* add test_to_datetime_numerical_input * check arg for numerical type
* add test_to_datetime_numerical_input * check arg for numerical type
* add test_to_datetime_numerical_input * check arg for numerical type
* Tests * add test_to_datetime_numerical_input * add fixtures * update bool tests * Check argument * for numerical type * DataFrame with unit
I made the changes to take into account all cases and updated the tests. def check_bool(arg):
arg = np.asarray(arg)
return ((arg == True) | (arg == False)).sum() In case of > 0 raising a ValueError but it seems a little overkill to me |
* Tests * add test_to_datetime_numerical_input * add fixtures * update bool tests * Check argument * for numerical type * DataFrame with unit
* Tests * add test_to_datetime_numerical_input * add fixtures * update bool tests * Check argument * for numerical type * DataFrame with unit
* Tests * add test_to_datetime_numerical_input * add fixtures * update bool tests * Check argument * for numerical type * DataFrame with unit
* Tests * add test_to_datetime_numerical_input * add fixtures * update bool tests * Check argument * for numerical type * DataFrame with unit
Related issue: #14350 |
All numerical types now need a unit in to_datetime call. * Update tests * Add bool verification in tslib.pyx * Bug correction with bool and unit in ['ms', 'us', 's', 'D'] * to_datetime(True, unit='ms') did run without error * to_datetime(True, unit='ms', errors='ignore') returned None Issue: pandas-dev#15836
All numerical types now need a unit in to_datetime call. * Update tests * Add bool verification in tslib.pyx * Bug correction with bool and unit in ['ms', 'us', 's', 'D'] * to_datetime(True, unit='ms') did run without error * to_datetime(True, unit='ms', errors='ignore') returned None Issue: pandas-dev#15836
All numerical types now need a unit in to_datetime call. * Update tests * Add bool verification in tslib.pyx * Bug correction with bool and unit in ['ms', 'us', 's', 'D'] * to_datetime(True, unit='ms') did run without error * to_datetime(True, unit='ms', errors='ignore') returned None Issue: pandas-dev#15836
All numerical types now need a unit in to_datetime call. * Update tests * Add bool verification in tslib.pyx * Bug correction with bool and unit in ['ms', 'us', 's', 'D'] * to_datetime(True, unit='ms') did run without error * to_datetime(True, unit='ms', errors='ignore') returned None Issue: pandas-dev#15836
xref #15828
Currently, if ordinals are passed to
to_datetime
without a unit, ans
resolution is assumed. Given relative rarity of ns ordinals in the wild, I've been tripped up by this, e.g., below. I wonder if it would be better to raise in the case of no unit, and force ordinal parsing to always be explicit?The text was updated successfully, but these errors were encountered: