Skip to content

Commit 186ce4e

Browse files
kittokujreback
authored andcommitted
BUG: Iteration over DatetimeIndex stops at chunksize (GH21012) (#21027)
1 parent 1a9937d commit 186ce4e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pandas/core/indexes/datetimes.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,8 @@ def __iter__(self):
13651365
converted = libts.ints_to_pydatetime(data[start_i:end_i],
13661366
tz=self.tz, freq=self.freq,
13671367
box="timestamp")
1368-
return iter(converted)
1368+
for v in converted:
1369+
yield v
13691370

13701371
def _wrap_union_result(self, other, result):
13711372
name = self.name if self.name == other.name else None

pandas/tests/indexes/datetimes/test_datetime.py

+11
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ def test_iteration_preserves_tz(self):
153153
assert result._repr_base == expected._repr_base
154154
assert result == expected
155155

156+
@pytest.mark.parametrize('periods', [0, 9999, 10000, 10001])
157+
def test_iteration_over_chunksize(self, periods):
158+
# GH21012
159+
160+
index = date_range('2000-01-01 00:00:00', periods=periods, freq='min')
161+
num = 0
162+
for stamp in index:
163+
assert index[num] == stamp
164+
num += 1
165+
assert num == len(index)
166+
156167
def test_misc_coverage(self):
157168
rng = date_range('1/1/2000', periods=5)
158169
result = rng.groupby(rng.day)

0 commit comments

Comments
 (0)