Skip to content

Commit

Permalink
TST: Clean / make tests more performant (#56108)
Browse files Browse the repository at this point in the history
CLN: Tests
  • Loading branch information
mroeschke authored Nov 22, 2023
1 parent 05c32ba commit 3f6b08b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
5 changes: 4 additions & 1 deletion pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
from pandas.core.arrays import PeriodArray


_ITER_CHUNKSIZE = 10_000


def tz_to_dtype(
tz: tzinfo | None, unit: str = "ns"
) -> np.dtype[np.datetime64] | DatetimeTZDtype:
Expand Down Expand Up @@ -654,7 +657,7 @@ def __iter__(self) -> Iterator:
# convert in chunks of 10k for efficiency
data = self.asi8
length = len(self)
chunksize = 10000
chunksize = _ITER_CHUNKSIZE
chunks = (length // chunksize) + 1

for i in range(chunks):
Expand Down
19 changes: 12 additions & 7 deletions pandas/tests/indexes/datetimes/test_iter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
date_range,
to_datetime,
)
from pandas.core.arrays import datetimes


class TestDatetimeIndexIteration:
Expand Down Expand Up @@ -59,13 +60,17 @@ def test_iteration_preserves_tz3(self):
assert result._repr_base == expected._repr_base
assert result == expected

@pytest.mark.parametrize("periods", [0, 9999, 10000, 10001])
def test_iteration_over_chunksize(self, periods):
@pytest.mark.parametrize("offset", [-5, -1, 0, 1])
def test_iteration_over_chunksize(self, offset, monkeypatch):
# GH#21012

index = date_range("2000-01-01 00:00:00", periods=periods, freq="min")
chunksize = 5
index = date_range(
"2000-01-01 00:00:00", periods=chunksize - offset, freq="min"
)
num = 0
for stamp in index:
assert index[num] == stamp
num += 1
with monkeypatch.context() as m:
m.setattr(datetimes, "_ITER_CHUNKSIZE", chunksize)
for stamp in index:
assert index[num] == stamp
num += 1
assert num == len(index)
2 changes: 1 addition & 1 deletion pandas/tests/resample/test_datetime_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,7 @@ def test_resample_equivalent_offsets(n1, freq1, n2, freq2, k, unit):
# GH 24127
n1_ = n1 * k
n2_ = n2 * k
dti = date_range("19910905 13:00", "19911005 07:00", freq=freq1).as_unit(unit)
dti = date_range("1991-09-05", "1991-09-12", freq=freq1).as_unit(unit)
ser = Series(range(len(dti)), index=dti)

result1 = ser.resample(str(n1_) + freq1).mean()
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/window/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,9 @@ def test_center_reindex_series(raw, series):
tm.assert_series_equal(series_xp, series_rs)


def test_center_reindex_frame(raw, frame):
def test_center_reindex_frame(raw):
# shifter index
frame = DataFrame(range(100), index=date_range("2020-01-01", freq="D", periods=100))
s = [f"x{x:d}" for x in range(12)]
minp = 10

Expand Down

0 comments on commit 3f6b08b

Please sign in to comment.