Skip to content

Commit 9766248

Browse files
wjandreakvnwng
authored and
kvnwng
committed
More idiomatic example code in BaseIndexer (pandas-dev#58356)
No need to loop when NumPy supports range and array addition
1 parent 233e76c commit 9766248

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

pandas/core/indexers/objects.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,8 @@ class BaseIndexer:
5353
>>> from pandas.api.indexers import BaseIndexer
5454
>>> class CustomIndexer(BaseIndexer):
5555
... def get_window_bounds(self, num_values, min_periods, center, closed, step):
56-
... start = np.empty(num_values, dtype=np.int64)
57-
... end = np.empty(num_values, dtype=np.int64)
58-
... for i in range(num_values):
59-
... start[i] = i
60-
... end[i] = i + self.window_size
56+
... start = np.arange(num_values, dtype=np.int64)
57+
... end = np.arange(num_values, dtype=np.int64) + self.window_size
6158
... return start, end
6259
>>> df = pd.DataFrame({"values": range(5)})
6360
>>> indexer = CustomIndexer(window_size=2)

0 commit comments

Comments
 (0)