-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
API: microsecond resolution for Timedelta strings #63196
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
Changes from 5 commits
f656e6b
887ded1
c2eac39
85a1745
d6e9464
a615d43
506db5c
8f9fca0
723cba8
8b8e0b9
a27706f
eec8818
01966a7
f4256bf
c48de7e
0664bd3
c9d22df
24b7a25
bb4c0cb
06d67ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||
| import collections | ||||||
| import re | ||||||
| import warnings | ||||||
|
|
||||||
| from pandas.util._decorators import set_module | ||||||
|
|
@@ -679,6 +680,17 @@ cdef timedelta_from_spec(object number, object frac, object unit): | |||||
| return cast_from_unit(float(n), unit) | ||||||
|
|
||||||
|
|
||||||
| cdef bint needs_nano_unit(int64_t ival, str item): | ||||||
| """ | ||||||
| Check if a passed string `item` needs to be stored with nano unit or can | ||||||
| use microsecond instead. | ||||||
| """ | ||||||
| # TODO: more performant way of doing this check? | ||||||
| if ival % 1000 != 0: | ||||||
| return True | ||||||
| return re.search(r"\.\d{7}", item) or "ns" in item or "nano" in item | ||||||
|
||||||
| return re.search(r"\.\d{7}", item) or "ns" in item or "nano" in item | |
| return re.search(r"\.\d{7}", item) or "ns" in item or "nano" in item.lower() |
(or add or "Nano" in item)
?
I was checking the Timedelta tests for the other PR, and seeing that we allow title case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I'm still chasing down the failures that are caused when we add this to the array inference. there are some actual bugs that uncovered.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,7 +147,7 @@ def test_len_nan_group(): | |
|
|
||
| def test_groupby_timedelta_median(): | ||
| # issue 57926 | ||
| expected = Series(data=Timedelta("1D"), index=["foo"]) | ||
| expected = Series(data=Timedelta("1D"), index=["foo"], dtype="m8[ns]") | ||
|
||
| df = DataFrame({"label": ["foo", "foo"], "timedelta": [pd.NaT, Timedelta("1D")]}) | ||
| gb = df.groupby("label")["timedelta"] | ||
| actual = gb.median() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -440,7 +440,7 @@ def test_td_mul_td64_ndarray_invalid(self): | |
|
|
||
| msg = ( | ||
| "ufunc '?multiply'? cannot use operands with types " | ||
| rf"dtype\('{tm.ENDIAN}m8\[ns\]'\) and dtype\('{tm.ENDIAN}m8\[ns\]'\)" | ||
| rf"dtype\('{tm.ENDIAN}m8\[us\]'\) and dtype\('{tm.ENDIAN}m8\[us\]'\)" | ||
| ) | ||
| with pytest.raises(TypeError, match=msg): | ||
| td * other | ||
|
|
@@ -1219,6 +1219,7 @@ def test_ops_str_deprecated(box): | |
| "ufunc 'divide' cannot use operands", | ||
| "Invalid dtype object for __floordiv__", | ||
| r"unsupported operand type\(s\) for /: 'int' and 'str'", | ||
| r"unsupported operand type\(s\) for /: 'datetime.timedelta' and 'str'", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, how is this caused by the changes here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was only on the dev builds and when box=True so we are dividing by |
||
| ] | ||
| ) | ||
| with pytest.raises(TypeError, match=msg): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.