Skip to content

BUG: Adds missing raises for numpy.timedelta64[M/Y] in pandas.Timedelta #53421

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

Merged
merged 27 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
41c9adc
adds raise for numpy Y and M conversion in Timedelta
mcgeestocks May 27, 2023
2221543
Merge branch 'main' into timedelta-raise
mcgeestocks May 28, 2023
90d34f5
fix failing tests
mcgeestocks May 29, 2023
36d2abf
Merge branch 'timedelta-raise' of github.com:mcgeestocks/pandas-mcgee…
mcgeestocks May 29, 2023
5db101b
Merge branch 'main' into timedelta-raise
mcgeestocks May 29, 2023
d5be260
Merge branch 'main' into timedelta-raise
mcgeestocks May 30, 2023
3259eb9
update raise lang
mcgeestocks May 30, 2023
cfc3451
Merge remote-tracking branch 'upstream/main' into timedelta-raise
mcgeestocks Jun 5, 2023
20dcb16
alternative approach
mcgeestocks Jun 5, 2023
cc48ef7
add missing periods
mcgeestocks Jun 7, 2023
af689be
Merge remote-tracking branch 'upstream/main' into timedelta-raise
mcgeestocks Jun 7, 2023
0589d34
Merge branch 'main' into timedelta-raise
mcgeestocks Jun 8, 2023
77a256c
switch to cimport
mcgeestocks Jun 9, 2023
97be59c
add cython directive
mcgeestocks Jun 9, 2023
2ae5b72
switch to inline cython directive
mcgeestocks Jun 9, 2023
86ace60
Merge branch 'main' into timedelta-raise
mcgeestocks Jun 9, 2023
69e1f96
remove unsupported td operation
mcgeestocks Jun 9, 2023
09fb208
adds whatnew update
mcgeestocks Jun 9, 2023
8fd2a31
Merge branch 'main' into timedelta-raise
mcgeestocks Jun 11, 2023
c603860
Merge branch 'main' into timedelta-raise
mcgeestocks Jun 12, 2023
6ccaadd
Merge remote-tracking branch 'upstream/main' into timedelta-raise
mcgeestocks Jun 19, 2023
cc1ec83
remove whitespace
mcgeestocks Jun 19, 2023
3057fe8
adds test
mcgeestocks Jun 19, 2023
73bcf11
Merge branch 'main' into timedelta-raise
mcgeestocks Jun 19, 2023
2afb107
Merge branch 'main' into timedelta-raise
mcgeestocks Jun 19, 2023
5b840a2
Merge branch 'main' into timedelta-raise
mcgeestocks Jun 19, 2023
1deec72
Merge branch 'main' into timedelta-raise
mcgeestocks Jun 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1739,8 +1739,10 @@ class Timedelta(_Timedelta):
+ int(kwargs.get("milliseconds", 0) * 1_000_000)
+ seconds
)

if unit in {"Y", "y", "M"}:
if unit in {"Y", "y", "M"} or (isinstance(value, np.timedelta64) and
get_datetime64_unit(value) in {
NPY_DATETIMEUNIT.NPY_FR_Y,
NPY_DATETIMEUNIT.NPY_FR_M}):
raise ValueError(
"Units 'M', 'Y', and 'y' are no longer supported, as they do not "
"represent unambiguous timedelta values durations."
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/libs/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_fast_multiget_timedelta_resos(self):
tm.assert_numpy_array_equal(result, expected)

# case that can't be cast to td64ns
td = Timedelta(np.timedelta64(400, "Y"))
td = Timedelta(np.timedelta64(146000, "D"))
assert hash(td) == hash(td.as_unit("ms"))
assert hash(td) == hash(td.as_unit("us"))
mapping1 = {td: 1}
Expand Down
2 changes: 0 additions & 2 deletions pandas/tests/scalar/timedelta/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ def test_overflow_on_construction():
@pytest.mark.parametrize(
"val, unit",
[
(3508, "M"),
(15251, "W"), # 1
(106752, "D"), # change from previous:
(2562048, "h"), # 0 hours
Expand Down Expand Up @@ -333,7 +332,6 @@ def test_construction_out_of_bounds_td64ns(val, unit):
@pytest.mark.parametrize(
"val, unit",
[
(3508 * 10**9, "M"),
(15251 * 10**9, "W"),
(106752 * 10**9, "D"),
(2562048 * 10**9, "h"),
Expand Down