Skip to content

Commit a738223

Browse files
topper-123jreback
authored andcommitted
CLN: remove compat.lrange (#26396)
1 parent 3b24fb6 commit a738223

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+213
-288
lines changed

pandas/compat/__init__.py

-8
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
55
Cross-compatible functions for different versions of Python.
66
7-
Key items to import for compatible code:
8-
* lists: lrange()
9-
107
Other items:
118
* platform checker
129
"""
@@ -19,11 +16,6 @@
1916
PYPY = platform.python_implementation() == 'PyPy'
2017

2118

22-
# list-producing versions of the major Python iterating functions
23-
def lrange(*args, **kwargs):
24-
return list(range(*args, **kwargs))
25-
26-
2719
# ----------------------------------------------------------------------------
2820
# functions largely based / taken from the six module
2921

pandas/plotting/_converter.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from pandas._libs import lib, tslibs
1313
from pandas._libs.tslibs import resolution
1414
from pandas._libs.tslibs.frequencies import FreqGroup, get_freq
15-
from pandas.compat import lrange
1615

1716
from pandas.core.dtypes.common import (
1817
is_datetime64_ns_dtype, is_float, is_float_dtype, is_integer,
@@ -1029,7 +1028,7 @@ def __call__(self):
10291028
base = self.base
10301029
(d, m) = divmod(vmin, base)
10311030
vmin = (d + 1) * base
1032-
locs = lrange(vmin, vmax + 1, base)
1031+
locs = list(range(vmin, vmax + 1, base))
10331032
return locs
10341033

10351034
def autoscale(self):

pandas/plotting/_core.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from pandas._config import get_option
1010

11-
from pandas.compat import lrange
1211
from pandas.errors import AbstractMethodError
1312
from pandas.util._decorators import Appender, cache_readonly
1413

@@ -583,9 +582,9 @@ def _get_xticks(self, convert_period=False):
583582
x = self.data.index._mpl_repr()
584583
else:
585584
self._need_to_set_index = True
586-
x = lrange(len(index))
585+
x = list(range(len(index)))
587586
else:
588-
x = lrange(len(index))
587+
x = list(range(len(index)))
589588

590589
return x
591590

pandas/plotting/_misc.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# being a bit too dynamic
22
import numpy as np
33

4-
from pandas.compat import lrange
54
from pandas.util._decorators import deprecate_kwarg
65

76
from pandas.core.dtypes.missing import notna
@@ -81,8 +80,8 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
8180
rdelta_ext = (rmax_ - rmin_) * range_padding / 2.
8281
boundaries_list.append((rmin_ - rdelta_ext, rmax_ + rdelta_ext))
8382

84-
for i, a in zip(lrange(n), df.columns):
85-
for j, b in zip(lrange(n), df.columns):
83+
for i, a in enumerate(df.columns):
84+
for j, b in enumerate(df.columns):
8685
ax = axes[i, j]
8786

8887
if i == j:
@@ -420,7 +419,7 @@ def bootstrap_plot(series, fig=None, size=50, samples=500, **kwds):
420419
for sampling in samplings])
421420
if fig is None:
422421
fig = plt.figure()
423-
x = lrange(samples)
422+
x = list(range(samples))
424423
axes = []
425424
ax1 = fig.add_subplot(2, 3, 1)
426425
ax1.set_xlabel("Sample")
@@ -532,7 +531,7 @@ def parallel_coordinates(frame, class_column, cols=None, ax=None, color=None,
532531
raise ValueError('Length of xticks must match number of columns')
533532
x = xticks
534533
else:
535-
x = lrange(ncols)
534+
x = list(range(ncols))
536535

537536
if ax is None:
538537
ax = plt.gca()

pandas/plotting/_style.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
import numpy as np
66

7-
from pandas.compat import lrange
8-
97
from pandas.core.dtypes.common import is_list_like
108

119

@@ -49,7 +47,7 @@ def random_color(column):
4947
rs = com.random_state(column)
5048
return rs.rand(3).tolist()
5149

52-
colors = [random_color(num) for num in lrange(num_colors)]
50+
colors = [random_color(num) for num in range(num_colors)]
5351
else:
5452
raise ValueError("color_type must be either 'default' or 'random'")
5553

pandas/tests/arrays/categorical/test_missing.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import numpy as np
44
import pytest
55

6-
from pandas.compat import lrange
7-
86
from pandas.core.dtypes.dtypes import CategoricalDtype
97

108
from pandas import Categorical, Index, isna
@@ -16,7 +14,7 @@ class TestCategoricalMissing:
1614
def test_na_flags_int_categories(self):
1715
# #1457
1816

19-
categories = lrange(10)
17+
categories = list(range(10))
2018
labels = np.random.randint(0, 10, 20)
2119
labels[::5] = -1
2220

pandas/tests/frame/test_duplicates.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
from pandas.compat import lrange
5-
64
from pandas import DataFrame, Series
75
import pandas.util.testing as tm
86

@@ -88,8 +86,8 @@ def test_drop_duplicates():
8886
'B': ['one', 'one', 'two', 'two',
8987
'two', 'two', 'one', 'two'],
9088
'C': [1, 1, 2, 2, 2, 2, 1, 2],
91-
'D': lrange(8)})
92-
89+
'D': range(8),
90+
})
9391
# single column
9492
result = df.drop_duplicates('AAA')
9593
expected = df[:2]
@@ -211,8 +209,8 @@ def test_drop_duplicates_for_take_all():
211209
'B': ['one', 'one', 'two', 'two',
212210
'two', 'two', 'one', 'two'],
213211
'C': [1, 1, 2, 2, 2, 2, 1, 2],
214-
'D': lrange(8)})
215-
212+
'D': range(8),
213+
})
216214
# single column
217215
result = df.drop_duplicates('AAA')
218216
expected = df.iloc[[0, 1, 2, 6]]
@@ -246,8 +244,8 @@ def test_drop_duplicates_tuple():
246244
'B': ['one', 'one', 'two', 'two',
247245
'two', 'two', 'one', 'two'],
248246
'C': [1, 1, 2, 2, 2, 2, 1, 2],
249-
'D': lrange(8)})
250-
247+
'D': range(8),
248+
})
251249
# single column
252250
result = df.drop_duplicates(('AA', 'AB'))
253251
expected = df[:2]
@@ -292,8 +290,8 @@ def test_drop_duplicates_NA():
292290
'B': ['one', 'one', 'two', 'two',
293291
'two', 'two', 'one', 'two'],
294292
'C': [1.0, np.nan, np.nan, np.nan, 1., 1., 1, 1.],
295-
'D': lrange(8)})
296-
293+
'D': range(8),
294+
})
297295
# single column
298296
result = df.drop_duplicates('A')
299297
expected = df.loc[[0, 2, 3]]
@@ -327,8 +325,8 @@ def test_drop_duplicates_NA():
327325
'B': ['one', 'one', 'two', 'two',
328326
'two', 'two', 'one', 'two'],
329327
'C': [1.0, np.nan, np.nan, np.nan, 1., 1., 1, 1.],
330-
'D': lrange(8)})
331-
328+
'D': range(8),
329+
})
332330
# single column
333331
result = df.drop_duplicates('C')
334332
expected = df[:2]
@@ -398,8 +396,8 @@ def test_drop_duplicates_inplace():
398396
'B': ['one', 'one', 'two', 'two',
399397
'two', 'two', 'one', 'two'],
400398
'C': [1, 1, 2, 2, 2, 2, 1, 2],
401-
'D': lrange(8)})
402-
399+
'D': range(8),
400+
})
403401
# single column
404402
df = orig.copy()
405403
df.drop_duplicates('A', inplace=True)

pandas/tests/indexes/datetimes/test_timezones.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import pytz
1212

1313
from pandas._libs.tslibs import conversion, timezones
14-
from pandas.compat import lrange
1514
import pandas.util._test_decorators as td
1615

1716
import pandas as pd
@@ -958,7 +957,7 @@ def test_dti_with_timezone_repr(self, tzstr):
958957
def test_dti_take_dont_lose_meta(self, tzstr):
959958
rng = date_range('1/1/2000', periods=20, tz=tzstr)
960959

961-
result = rng.take(lrange(5))
960+
result = rng.take(range(5))
962961
assert result.tz == rng.tz
963962
assert result.freq == rng.freq
964963

pandas/tests/indexes/multi/test_analytics.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
from pandas.compat import lrange
54
from pandas.compat.numpy import _np_version_under1p17
65

76
import pandas as pd
@@ -32,8 +31,8 @@ def test_groupby(idx):
3231

3332

3433
def test_truncate():
35-
major_axis = Index(lrange(4))
36-
minor_axis = Index(lrange(2))
34+
major_axis = Index(list(range(4)))
35+
minor_axis = Index(list(range(2)))
3736

3837
major_codes = np.array([0, 0, 1, 2, 3, 3])
3938
minor_codes = np.array([0, 1, 0, 1, 0, 1])

pandas/tests/indexes/multi/test_constructor.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import pytest
55

66
from pandas._libs.tslib import Timestamp
7-
from pandas.compat import lrange
87

98
from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
109

@@ -383,7 +382,7 @@ def test_from_product_empty_two_levels(first, second):
383382
def test_from_product_empty_three_levels(N):
384383
# GH12258
385384
names = ['A', 'B', 'C']
386-
lvl2 = lrange(N)
385+
lvl2 = list(range(N))
387386
result = MultiIndex.from_product([[], lvl2, []], names=names)
388387
expected = MultiIndex(levels=[[], lvl2, []],
389388
codes=[[], [], []], names=names)

pandas/tests/indexes/multi/test_drop.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
from pandas.compat import lrange
54
from pandas.errors import PerformanceWarning
65

76
import pandas as pd
@@ -73,9 +72,10 @@ def test_droplevel_with_names(idx):
7372
assert dropped.name == 'second'
7473

7574
index = MultiIndex(
76-
levels=[Index(lrange(4)), Index(lrange(4)), Index(lrange(4))],
77-
codes=[np.array([0, 0, 1, 2, 2, 2, 3, 3]), np.array(
78-
[0, 1, 0, 0, 0, 1, 0, 1]), np.array([1, 0, 1, 1, 0, 0, 1, 0])],
75+
levels=[Index(range(4)), Index(range(4)), Index(range(4))],
76+
codes=[np.array([0, 0, 1, 2, 2, 2, 3, 3]),
77+
np.array([0, 1, 0, 0, 0, 1, 0, 1]),
78+
np.array([1, 0, 1, 1, 0, 0, 1, 0])],
7979
names=['one', 'two', 'three'])
8080
dropped = index.droplevel(0)
8181
assert dropped.names == ('two', 'three')
@@ -87,9 +87,10 @@ def test_droplevel_with_names(idx):
8787

8888
def test_droplevel_list():
8989
index = MultiIndex(
90-
levels=[Index(lrange(4)), Index(lrange(4)), Index(lrange(4))],
91-
codes=[np.array([0, 0, 1, 2, 2, 2, 3, 3]), np.array(
92-
[0, 1, 0, 0, 0, 1, 0, 1]), np.array([1, 0, 1, 1, 0, 0, 1, 0])],
90+
levels=[Index(range(4)), Index(range(4)), Index(range(4))],
91+
codes=[np.array([0, 0, 1, 2, 2, 2, 3, 3]),
92+
np.array([0, 1, 0, 0, 0, 1, 0, 1]),
93+
np.array([1, 0, 1, 1, 0, 0, 1, 0])],
9394
names=['one', 'two', 'three'])
9495

9596
dropped = index[:2].droplevel(['three', 'one'])

pandas/tests/indexes/multi/test_equivalence.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
from pandas.compat import lrange
5-
64
import pandas as pd
75
from pandas import Index, MultiIndex, Series
86
import pandas.util.testing as tm
@@ -96,17 +94,21 @@ def test_equals_multi(idx):
9694
assert not idx.equals(idx[-1])
9795

9896
# different number of levels
99-
index = MultiIndex(levels=[Index(lrange(4)), Index(lrange(4)), Index(
100-
lrange(4))], codes=[np.array([0, 0, 1, 2, 2, 2, 3, 3]), np.array(
101-
[0, 1, 0, 0, 0, 1, 0, 1]), np.array([1, 0, 1, 1, 0, 0, 1, 0])])
97+
index = MultiIndex(levels=[Index(list(range(4))),
98+
Index(list(range(4))),
99+
Index(list(range(4)))],
100+
codes=[np.array([0, 0, 1, 2, 2, 2, 3, 3]),
101+
np.array([0, 1, 0, 0, 0, 1, 0, 1]),
102+
np.array([1, 0, 1, 1, 0, 0, 1, 0])],
103+
)
102104

103105
index2 = MultiIndex(levels=index.levels[:-1], codes=index.codes[:-1])
104106
assert not index.equals(index2)
105107
assert not index.equal_levels(index2)
106108

107109
# levels are different
108-
major_axis = Index(lrange(4))
109-
minor_axis = Index(lrange(2))
110+
major_axis = Index(list(range(4)))
111+
minor_axis = Index(list(range(2)))
110112

111113
major_codes = np.array([0, 0, 1, 2, 2, 3])
112114
minor_codes = np.array([0, 1, 0, 0, 1, 0])
@@ -178,14 +180,14 @@ def test_is_():
178180
mi2.set_names(["E", "F"], inplace=True)
179181
assert mi.is_(mi2)
180182
# levels are inherent properties, they change identity
181-
mi3 = mi2.set_levels([lrange(10), lrange(10)])
183+
mi3 = mi2.set_levels([list(range(10)), list(range(10))])
182184
assert not mi3.is_(mi2)
183185
# shouldn't change
184186
assert mi2.is_(mi)
185187
mi4 = mi3.view()
186188

187189
# GH 17464 - Remove duplicate MultiIndex levels
188-
mi4.set_levels([lrange(10), lrange(10)], inplace=True)
190+
mi4.set_levels([list(range(10)), list(range(10))], inplace=True)
189191
assert not mi4.is_(mi3)
190192
mi5 = mi.view()
191193
mi5.set_levels(mi5.levels, inplace=True)

0 commit comments

Comments
 (0)