Skip to content

Commit 1d5e451

Browse files
committed
CLN: remove uses of compat.lrange, part I
1 parent f46ab96 commit 1d5e451

File tree

8 files changed

+23
-26
lines changed

8 files changed

+23
-26
lines changed

Diff for: pandas/core/generic.py

+3-3
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 sentinel:
13001300
continue

Diff for: pandas/core/indexes/multi.py

+2-2
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'

Diff for: pandas/core/indexes/range.py

+1-2
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):

Diff for: pandas/core/internals/construction.py

+2-2
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)

Diff for: pandas/core/reshape/concat.py

+1-1
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):

Diff for: pandas/core/reshape/pivot.py

+1-2
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)

Diff for: pandas/io/pytables.py

+1-2
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

Diff for: pandas/tests/groupby/test_groupby.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77
import pytest
88

9-
from pandas.compat import lmap, lrange, lzip
9+
from pandas.compat import lmap, lzip
1010
from pandas.errors import PerformanceWarning
1111

1212
import pandas as pd
@@ -84,7 +84,7 @@ def test_groupby_nonobject_dtype(mframe, df_mixed_floats):
8484

8585
# GH 3911, mixed frame non-conversion
8686
df = df_mixed_floats.copy()
87-
df['value'] = lrange(len(df))
87+
df['value'] = range(len(df))
8888

8989
def max_value(group):
9090
return group.loc[group['value'].idxmax()]
@@ -249,11 +249,11 @@ def test_len():
249249

250250
def test_basic_regression():
251251
# regression
252-
T = [1.0 * x for x in lrange(1, 10) * 10][:1095]
253-
result = Series(T, lrange(0, len(T)))
252+
T = [1.0 * x for x in list(range(1, 10)) * 10][:1095]
253+
result = Series(T, index=range(len(T)))
254254

255255
groupings = np.random.random((1100, ))
256-
groupings = Series(groupings, lrange(0, len(groupings))) * 10.
256+
groupings = Series(groupings, index=range(len(groupings))) * 10.
257257

258258
grouped = result.groupby(groupings)
259259
grouped.mean()
@@ -320,9 +320,9 @@ def f3(x):
320320
else:
321321
return y
322322

323-
df = DataFrame({'a': [1, 2, 2, 2], 'b': lrange(4), 'c': lrange(5, 9)})
323+
df = DataFrame({'a': [1, 2, 2, 2], 'b': range(4), 'c': range(5, 9)})
324324

325-
df2 = DataFrame({'a': [3, 2, 2, 2], 'b': lrange(4), 'c': lrange(5, 9)})
325+
df2 = DataFrame({'a': [3, 2, 2, 2], 'b': range(4), 'c': range(5, 9)})
326326

327327
# correct result
328328
result1 = df.groupby('a').apply(f1)
@@ -875,7 +875,7 @@ def test_mutate_groups():
875875
'cat1': ['a'] * 8 + ['b'] * 6,
876876
'cat2': ['c'] * 2 + ['d'] * 2 + ['e'] * 2 + ['f'] * 2 + ['c'] * 2 +
877877
['d'] * 2 + ['e'] * 2,
878-
'cat3': lmap(lambda x: 'g%s' % x, lrange(1, 15)),
878+
'cat3': lmap(lambda x: 'g%s' % x, range(1, 15)),
879879
'val': np.random.randint(100, size=14),
880880
})
881881

@@ -1063,8 +1063,8 @@ def test_groupby_mixed_type_columns():
10631063
def test_cython_grouper_series_bug_noncontig():
10641064
arr = np.empty((100, 100))
10651065
arr.fill(np.nan)
1066-
obj = Series(arr[:, 0], index=lrange(100))
1067-
inds = np.tile(lrange(10), 10)
1066+
obj = Series(arr[:, 0], index=range(100))
1067+
inds = np.tile(range(10), 10)
10681068

10691069
result = obj.groupby(inds).agg(Series.median)
10701070
assert result.isna().all()
@@ -1086,7 +1086,7 @@ def test_series_grouper_noncontig_index():
10861086

10871087
def test_convert_objects_leave_decimal_alone():
10881088

1089-
s = Series(lrange(5))
1089+
s = Series(range(5))
10901090
labels = np.array(['a', 'b', 'c', 'd', 'e'], dtype='O')
10911091

10921092
def convert_fast(x):
@@ -1217,7 +1217,7 @@ def test_groupby_nat_exclude():
12171217

12181218

12191219
def test_groupby_2d_malformed():
1220-
d = DataFrame(index=lrange(2))
1220+
d = DataFrame(index=range(2))
12211221
d['group'] = ['g1', 'g2']
12221222
d['zeros'] = [0, 0]
12231223
d['ones'] = [1, 1]

0 commit comments

Comments
 (0)