8000 CLN: remove uses of compat.lrange, part I (#26281) · pandas-dev/pandas@8ac3123 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8ac3123

Browse files
topper-123jschendel
authored andcommitted
CLN: remove uses of compat.lrange, part I (#26281)
1 parent 560ad35 commit 8ac3123

File tree

17 files changed

+45
-55
lines changed

17 files changed

+45
-55
lines changed

pandas/core/generic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from pandas._config import config
1616

1717
from pandas._libs import Timestamp, iNaT, properties
18-
from pandas.compat import lrange, lzip, set_function_name, to_str
18+
from pandas.compat import lzip, set_function_name, to_str
1919
from pandas.compat.numpy import function as nv
2020
from pandas.errors import AbstractMethodError
2121
from pandas.util._decorators import (
@@ -1101,7 +1101,7 @@ def rename(self, *args, **kwargs):
11011101
result = self if inplace else self.copy(deep=copy)
11021102

11031103
# start in the axis order to eliminate too many copies
1104-
for axis in lrange(self._AXIS_LEN):
1104+
for axis in range(self._AXIS_LEN):
11051105
v = axes.get(self._AXIS_NAMES[axis])
11061106
if v is None:
11071107
continue
@@ -1294,7 +1294,7 @@ class name
12941294
# is specified
12951295
result = self if inplace else self.copy(deep=copy)
12961296

1297-
for axis in lrange(self._AXIS_LEN):
1297+
for axis in range(self._AXIS_LEN):
12981298
v = axes.get(self._AXIS_NAMES[axis])
12991299
if v is< 579F /span> sentinel:
13001300
continue

pandas/core/indexes/multi.py

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

1010
from pandas._libs import (
1111
Timestamp, algos as libalgos, index as libindex, lib, tslibs)
12-
from pandas.compat import lrange, lzip
12+
from pandas.compat import lzip
1313
from pandas.compat.numpy import function as nv
1414
from pandas.errors import PerformanceWarning, UnsortedIndexError
1515
from pandas.util._decorators import Appender, cache_readonly, deprecate_kwarg
@@ -1913,7 +1913,7 @@ def drop(self, codes, level=None, errors='raise'):
19131913
if isinstance(loc, int):
19141914
inds.append(loc)
19151915
elif isinstance(loc, slice):
1916-
inds.extend(lrange(loc.start, loc.stop))
1916+
inds.extend(range(loc.start, loc.stop))
19171917
elif com.is_bool_indexer(loc):
19181918
if self.lexsort_depth == 0:
19191919
warnings.warn('dropping on a non-lexsorted multi-index'

pandas/core/indexes/range.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from pandas._libs import index as libindex, lib
99
import pandas.compat as compat
10-
from pandas.compat import lrange
1110
from pandas.compat.numpy import function as nv
1211
from pandas.util._decorators import Appender, cache_readonly
1312

@@ -292,7 +291,7 @@ def has_duplicates(self):
292291
return False
293292

294293
def tolist(self):
295-
return lrange(self._start, self._stop, self._step)
294+
return list(range(self._start, self._stop, self._step))
296295

297296
@Appender(_index_shared_docs['_shallow_copy'])
298297
def _shallow_copy(self, values=None, **kwargs):

pandas/core/internals/construction.py

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

1010
from pandas._libs import lib
1111
from pandas._libs.tslibs import IncompatibleFrequency
12-
from pandas.compat import lmap, lrange, raise_with_traceback
12+
from pandas.compat import lmap, raise_with_traceback
1313

1414
from pandas.core.dtypes.cast import (
1515
construct_1d_arraylike_from_scalar, construct_1d_ndarray_preserving_na,
@@ -339,7 +339,7 @@ def get_names_from_index(data):
339339
if not has_some_name:
340340
return ibase.default_index(len(data))
341341

342-
index = lrange(len(data))
342+
index = list(range(len(data)))
343343
count = 0
344344
for i, s in enumerate(data):
345345
n = getattr(s, 'name', None)

pandas/core/reshape/concat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def _get_new_axes(self):
452452
"to {length}".format(length=ndim - 1))
453453

454454
# ufff...
455-
indices = compat.lrange(ndim)
455+
indices = list(range(ndim))
456456
indices.remove(self.axis)
457457

458458
for i, ax in zip(indices, self.join_axes):

pandas/core/reshape/pivot.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import numpy as np
22

3-
from pandas.compat import lrange
43
from pandas.util._decorators import Appender, Substitution
54

65
from pandas.core.dtypes.cast import maybe_downcast_to_dtype
@@ -303,7 +302,7 @@ def _all_key(key):
303302
row_margin = row_margin.stack()
304303

305304
# slight hack
306-
new_order = [len(cols)] + lrange(len(cols))
305+
new_order = [len(cols)] + list(range(len(cols)))
307306
row_margin.index = row_margin.index.reorder_levels(new_order)
308307
else:
309308
row_margin = Series(np.nan, index=result.columns)

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/pytables.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
from pandas._libs import lib, writers as libwriters
2020
from pandas._libs.tslibs import timezones
21-
from pandas.compat import lrange
2221
from pandas.errors import PerformanceWarning
2322

2423
from pandas.core.dtypes.common import (
@@ -4101,7 +4100,7 @@ def delete(self, where=None, start=None, stop=None, **kwargs):
41014100
# we must remove in reverse order!
41024101
pg = groups.pop()
41034102
for g in reversed(groups):
4104-
rows = sorted_series.take(lrange(g, pg))
4103+
rows = sorted_series.take(range(g, pg))
41054104
table.remove_rows(start=rows[rows.index[0]
41064105
], stop=rows[rows.index[-1]] + 1)
41074106
pg = g

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
[

0 commit comments

Comments
 (0)
0