Skip to content

Commit 6926029

Browse files
committed
CLN: remove more uses of compat.lrange
1 parent 0b0642c commit 6926029

File tree

9 files changed

+22
-28
lines changed

9 files changed

+22
-28
lines changed

pandas/io/excel/_util.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import warnings
22

3-
from pandas.compat import lrange
4-
53
from pandas.core.dtypes.common import is_integer, is_list_like
64

75
_writers = {}
@@ -112,7 +110,7 @@ def _range2cols(areas):
112110
for rng in areas.split(","):
113111
if ":" in rng:
114112
rng = rng.split(":")
115-
cols.extend(lrange(_excel2num(rng[0]), _excel2num(rng[1]) + 1))
113+
cols.extend(range(_excel2num(rng[0]), _excel2num(rng[1]) + 1))
116114
else:
117115
cols.append(_excel2num(rng))
118116

@@ -141,7 +139,7 @@ def _maybe_convert_usecols(usecols):
141139
"deprecated. Please pass in a list of int from "
142140
"0 to `usecols` inclusive instead."),
143141
FutureWarning, stacklevel=2)
144-
return lrange(usecols + 1)
142+
return list(range(usecols + 1))
145143

146144
if isinstance(usecols, str):
147145
return _range2cols(usecols)

pandas/io/html.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os
1010
import re
1111

12-
from pandas.compat import lmap, lrange, raise_with_traceback
12+
from pandas.compat import lmap, raise_with_traceback
1313
from pandas.errors import AbstractMethodError, EmptyDataError
1414

1515
from pandas.core.dtypes.common import is_list_like
@@ -101,7 +101,8 @@ def _get_skiprows(skiprows):
101101
A proper iterator to use to skip rows of a DataFrame.
102102
"""
103103
if isinstance(skiprows, slice):
104-
return lrange(skiprows.start or 0, skiprows.stop, skiprows.step or 1)
104+
start, step = skiprows.start or 0, skiprows.step or 1
105+
return list(range(start, skiprows.stop, step))
105106
elif isinstance(skiprows, numbers.Integral) or is_list_like(skiprows):
106107
return skiprows
107108
elif skiprows is None:

pandas/io/stata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from pandas._libs.lib import infer_dtype
2525
from pandas._libs.writers import max_len_string_array
26-
from pandas.compat import lmap, lrange, lzip
26+
from pandas.compat import lmap, lzip
2727
from pandas.util._decorators import Appender, deprecate_kwarg
2828

2929
from pandas.core.dtypes.common import (
@@ -874,7 +874,7 @@ def __init__(self):
874874
(65530, np.int8)
875875
]
876876
)
877-
self.TYPE_MAP = lrange(251) + list('bhlfd')
877+
self.TYPE_MAP = list(range(251)) + list('bhlfd')
878878
self.TYPE_MAP_XML = \
879879
dict(
880880
[

pandas/tests/groupby/test_apply.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66

77
import pandas as pd
8-
from pandas import DataFrame, Index, MultiIndex, Series, bdate_range, compat
8+
from pandas import DataFrame, Index, MultiIndex, Series, bdate_range
99
from pandas.util import testing as tm
1010

1111

@@ -340,7 +340,7 @@ def f(group):
340340
def test_apply_chunk_view():
341341
# Low level tinkering could be unsafe, make sure not
342342
df = DataFrame({'key': [1, 1, 1, 2, 2, 2, 3, 3, 3],
343-
'value': compat.lrange(9)})
343+
'value': range(9)})
344344

345345
result = df.groupby('key', group_keys=False).apply(lambda x: x[:2])
346346
expected = df.take([0, 1, 3, 4, 6, 7])
@@ -350,7 +350,7 @@ def test_apply_chunk_view():
350350
def test_apply_no_name_column_conflict():
351351
df = DataFrame({'name': [1, 1, 1, 1, 1, 1, 2, 2, 2, 2],
352352
'name2': [0, 0, 0, 1, 1, 1, 0, 0, 1, 1],
353-
'value': compat.lrange(10)[::-1]})
353+
'value': list(range(10))[::-1]})
354354

355355
# it works! #2605
356356
grouped = df.groupby(['name', 'name2'])

pandas/tests/groupby/test_grouping.py

Lines changed: 1 addition & 3 deletions
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
import pandas as pd
97
from pandas import (
108
CategoricalIndex, DataFrame, Index, MultiIndex, Series, Timestamp,
@@ -481,7 +479,7 @@ def test_groupby_level(self, sort, mframe, df):
481479
def test_groupby_level_index_names(self):
482480
# GH4014 this used to raise ValueError since 'exp'>1 (in py2)
483481
df = DataFrame({'exp': ['A'] * 3 + ['B'] * 3,
484-
'var1': lrange(6), }).set_index('exp')
482+
'var1': range(6), }).set_index('exp')
485483
df.groupby(level='exp')
486484
msg = "level name foo is not the name of the index"
487485
with pytest.raises(ValueError, match=msg):

pandas/tests/groupby/test_nth.py

Lines changed: 2 additions & 4 deletions
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 DataFrame, Index, MultiIndex, Series, Timestamp, isna
86
from pandas.util.testing import (
@@ -84,9 +82,9 @@ def test_first_last_nth_dtypes(df_mixed_floats):
8482
assert_frame_equal(nth, expected)
8583

8684
# GH 2763, first/last shifting dtypes
87-
idx = lrange(10)
85+
idx = list(range(10))
8886
idx.append(9)
89-
s = Series(data=lrange(11), index=idx, name='IntCol')
87+
s = Series(data=range(11), index=idx, name='IntCol')
9088
assert s.dtype == 'int64'
9189
f = s.groupby(level=0).first()
9290
assert f.dtype == 'int64'

pandas/tests/indexes/multi/test_sorting.py

Lines changed: 1 addition & 2 deletions
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, UnsortedIndexError
65

76
import pandas as pd
@@ -97,7 +96,7 @@ def test_unsortedindex():
9796
mi = pd.MultiIndex.from_tuples([('z', 'a'), ('x', 'a'), ('y', 'b'),
9897
('x', 'b'), ('y', 'a'), ('z', 'b')],
9998
names=['one', 'two'])
100-
df = pd.DataFrame([[i, 10 * i] for i in lrange(6)], index=mi,
99+
df = pd.DataFrame([[i, 10 * i] for i in range(6)], index=mi,
101100
columns=['one', 'two'])
102101

103102
# GH 16734: not sorted, but no real slicing

pandas/tests/test_multilevel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pytest
1010
import pytz
1111

12-
from pandas.compat import lrange, lzip
12+
from pandas.compat import lzip
1313

1414
from pandas.core.dtypes.common import is_float_dtype, is_integer_dtype
1515

@@ -127,8 +127,8 @@ def test_series_constructor(self):
127127
multi = Series(1., index=[['a', 'a', 'b', 'b'], ['x', 'y', 'x', 'y']])
128128
assert isinstance(multi.index, MultiIndex)
129129

130-
multi = Series(lrange(4), index=[['a', 'a', 'b', 'b'],
131-
['x', 'y', 'x', 'y']])
130+
multi = Series(range(4), index=[['a', 'a', 'b', 'b'],
131+
['x', 'y', 'x', 'y']])
132132
assert isinstance(multi.index, MultiIndex)
133133

134134
def test_reindex_level(self):
@@ -1317,7 +1317,7 @@ def test_unicode_repr_level_names(self):
13171317
index = MultiIndex.from_tuples([(0, 0), (1, 1)],
13181318
names=['\u0394', 'i1'])
13191319

1320-
s = Series(lrange(2), index=index)
1320+
s = Series(range(2), index=index)
13211321
df = DataFrame(np.random.randn(2, 4), index=index)
13221322
repr(s)
13231323
repr(df)

pandas/util/testing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
can_set_locale, get_locales, set_locale)
2323

2424
from pandas._libs import testing as _testing
25-
from pandas.compat import lmap, lrange, lzip, raise_with_traceback
25+
from pandas.compat import lmap, lzip, raise_with_traceback
2626

2727
from pandas.core.dtypes.common import (
2828
is_bool, is_categorical_dtype, is_datetime64_dtype, is_datetime64tz_dtype,
@@ -364,7 +364,7 @@ def randbool(size=(), p=0.5):
364364

365365
RANDS_CHARS = np.array(list(string.ascii_letters + string.digits),
366366
dtype=(np.str_, 1))
367-
RANDU_CHARS = np.array(list("".join(map(chr, lrange(1488, 1488 + 26))) +
367+
RANDU_CHARS = np.array(list("".join(map(chr, range(1488, 1488 + 26))) +
368368
string.digits), dtype=(np.unicode_, 1))
369369

370370

@@ -1592,11 +1592,11 @@ def makeBoolIndex(k=10, name=None):
15921592

15931593

15941594
def makeIntIndex(k=10, name=None):
1595-
return Index(lrange(k), name=name)
1595+
return Index(list(range(k)), name=name)
15961596

15971597

15981598
def makeUIntIndex(k=10, name=None):
1599-
return Index([2**63 + i for i in lrange(k)], name=name)
1599+
return Index([2**63 + i for i in range(k)], name=name)
16001600

16011601

16021602
def makeRangeIndex(k=10, name=None, **kwargs):

0 commit comments

Comments
 (0)