10000 BUG: Fix a bug in 'timedelta_range' that produced an extra point on a edge case (fix #30353) by hasB4K · Pull Request #33498 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix a bug in 'timedelta_range' that produced an extra point on a edge case (fix #30353) #33498

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 17 commits into from
May 9, 2020
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
TST: remove the mock of timedelta_range with date_range
  • Loading branch information
hasB4K committed May 9, 2020
commit 71438d6f7509191d532b60dbb6359b4c0bb87f24
34 changes: 11 additions & 23 deletions pandas/tests/indexes/timedeltas/test_timedelta_range.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest

from pandas import Timedelta, Timestamp, date_range, timedelta_range, to_timedelta
from pandas import Timedelta, timedelta_range, to_timedelta
import pandas._testing as tm

from pandas.tseries.offsets import Day, Second
Expand Down Expand Up @@ -63,31 +63,19 @@ def test_errors(self):
timedelta_range(start="0 days", end="5 days", periods=10, freq="H")

@pytest.mark.parametrize(
"start, end, freq",
"start, end, freq, expected_periods",
[
("1D", "10D", "2D"),
("2D", "30D", "3D"),
("2s", "50s", "5s"),
("1D", "10D", "2D", (10 - 1) // 2 + 1),
("2D", "30D", "3D", (30 - 2) // 3 + 1),
("2s", "50s", "5s", (50 - 2) // 5 + 1),
# tests that worked before GH 33498:
("4D", "16D", "3D"),
("8D", "16D", "40s"),
("4D", "16D", "3D", (16 - 4) // 3 + 1),
("8D", "16D", "40s", (16 * 3600 * 24 - 8 * 3600 * 24) // 40 + 1),
],
)
def test_timedelta_range_freq_divide_end(self, start, end, freq):
def test_timedelta_range_freq_divide_end(self, start, end, freq, expected_periods):
# GH 33498 only the cases where `(end % freq) == 0` used to fail

def mock_timedelta_range(start=None, end=None, **kwargs):
epoch = Timestamp(0)
if start is not None:
start = epoch + Timedelta(start)
if end is not None:
end = epoch + Timedelta(end)
result = date_range(start=start, end=end, **kwargs) - epoch
result.freq = freq
return result

res = timedelta_range(start=start, end=end, freq=freq)
exp = mock_timedelta_range(start=start, end=end, freq=freq)

tm.assert_index_equal(res, exp)
assert res.freq == exp.freq
assert Timedelta(start) == res[0]
assert Timedelta(end) >= res[-1]
assert len(res) == expected_periods
0