Skip to content

Commit 87df599

Browse files
topper-123jreback
authored andcommitted
CLN: remove compat.lrange, part II (#26289)
1 parent 8fe33c9 commit 87df599

File tree

10 files changed

+60
-67
lines changed

10 files changed

+60
-67
lines changed

pandas/io/parsers.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import pandas._libs.parsers as parsers
1919
from pandas._libs.tslibs import parsing
2020
import pandas.compat as compat
21-
from pandas.compat import lrange, lzip
21+
from pandas.compat import lzip
2222
from pandas.errors import (
2323
AbstractMethodError, EmptyDataError, ParserError, ParserWarning)
2424
from pandas.util._decorators import Appender
@@ -1105,7 +1105,7 @@ def _clean_options(self, options, engine):
11051105
# c-engine, so only need for python parsers
11061106
if engine != 'c':
11071107
if is_integer(skiprows):
1108-
skiprows = lrange(skiprows)
1108+
skiprows = list(range(skiprows))
11091109
if skiprows is None:
11101110
skiprows = set()
11111111
elif not callable(skiprows):
@@ -1883,7 +1883,7 @@ def __init__(self, src, **kwds):
18831883
self.names = ['{prefix}{i}'.format(prefix=self.prefix, i=i)
18841884
for i in range(self._reader.table_width)]
18851885
else:
1886-
self.names = lrange(self._reader.table_width)
1886+
self.names = list(range(self._reader.table_width))
18871887

18881888
# gh-9755
18891889
#
@@ -1906,7 +1906,7 @@ def __init__(self, src, **kwds):
19061906
# GH 25623
19071907
# validate that column indices in usecols are not out of bounds
19081908
elif self.usecols_dtype == 'integer':
1909-
indices = lrange(self._reader.table_width)
1909+
indices = range(self._reader.table_width)
19101910
_validate_usecols_names(usecols, indices)
19111911

19121912
if len(self.names) > len(usecols):
@@ -2607,7 +2607,7 @@ def _infer_columns(self):
26072607
# validate that column indices in usecols are not out of bounds
26082608
if self.usecols_dtype == 'integer':
26092609
for col in columns:
2610-
indices = lrange(len(col))
2610+
indices = range(len(col))
26112611
_validate_usecols_names(self.usecols, indices)
26122612

26132613
if names is not None:
@@ -2648,14 +2648,14 @@ def _infer_columns(self):
26482648
# GH 25623
26492649
# validate that column indices in usecols are not out of bounds
26502650
if self.usecols_dtype == 'integer':
2651-
_validate_usecols_names(self.usecols, lrange(ncols))
2651+
_validate_usecols_names(self.usecols, range(ncols))
26522652

26532653
if not names:
26542654
if self.prefix:
26552655
columns = [['{prefix}{idx}'.format(
26562656
prefix=self.prefix, idx=i) for i in range(ncols)]]
26572657
else:
2658-
columns = [lrange(ncols)]
2658+
columns = [list(range(ncols))]
26592659
columns = self._handle_usecols(columns, columns[0])
26602660
else:
26612661
if self.usecols is None or len(names) >= num_original_columns:
@@ -3007,7 +3007,7 @@ def _get_index_name(self, columns):
30073007
if next_line is not None:
30083008
if len(next_line) == len(line) + self.num_original_columns:
30093009
# column and index names on diff rows
3010-
self.index_col = lrange(len(line))
3010+
self.index_col = list(range(len(line)))
30113011
self.buf = self.buf[1:]
30123012

30133013
for c in reversed(line):
@@ -3022,7 +3022,7 @@ def _get_index_name(self, columns):
30223022
# Case 1
30233023
self._implicit_index = True
30243024
if self.index_col is None:
3025-
self.index_col = lrange(implicit_first_cols)
3025+
self.index_col = list(range(implicit_first_cols))
30263026

30273027
index_name = None
30283028

pandas/tests/frame/test_query_eval.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import numpy as np
55
import pytest
66

7-
from pandas.compat import lrange
87
import pandas.util._test_decorators as td
98

109
import pandas as pd
@@ -460,8 +459,8 @@ def test_date_query_with_non_date(self):
460459

461460
def test_query_syntax_error(self):
462461
engine, parser = self.engine, self.parser
463-
df = DataFrame({"i": lrange(10), "+": lrange(3, 13),
464-
"r": lrange(4, 14)})
462+
df = DataFrame({"i": range(10), "+": range(3, 13),
463+
"r": range(4, 14)})
465464
with pytest.raises(SyntaxError):
466465
df.query('i - +', engine=engine, parser=parser)
467466

pandas/tests/frame/test_to_csv.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66
import pytest
77

8-
from pandas.compat import lmap, lrange
8+
from pandas.compat import lmap
99
from pandas.errors import ParserError
1010

1111
import pandas as pd
@@ -69,8 +69,8 @@ def test_to_csv_from_csv1(self):
6969
assert_almost_equal(self.tsframe.values, recons.values)
7070

7171
# corner case
72-
dm = DataFrame({'s1': Series(lrange(3), lrange(3)),
73-
's2': Series(lrange(2), lrange(2))})
72+
dm = DataFrame({'s1': Series(range(3), index=np.arange(3)),
73+
's2': Series(range(2), index=np.arange(2))})
7474
dm.to_csv(path)
7575

7676
recons = self.read_csv(path)
@@ -259,8 +259,8 @@ def _do_test(df, r_dtype=None, c_dtype=None,
259259
kwargs = dict(parse_dates=False)
260260
if cnlvl:
261261
if rnlvl is not None:
262-
kwargs['index_col'] = lrange(rnlvl)
263-
kwargs['header'] = lrange(cnlvl)
262+
kwargs['index_col'] = list(range(rnlvl))
263+
kwargs['header'] = list(range(cnlvl))
264264

265265
with ensure_clean('__tmp_to_csv_moar__') as path:
266266
df.to_csv(path, encoding='utf8',
@@ -392,7 +392,7 @@ def _to_uni(x):
392392
df.columns = cols
393393
_do_test(df, dupe_col=True)
394394

395-
_do_test(DataFrame(index=lrange(10)))
395+
_do_test(DataFrame(index=np.arange(10)))
396396
_do_test(mkdf(chunksize // 2 + 1, 2, r_idx_nlevels=2), rnlvl=2)
397397
for ncols in [2, 3, 4]:
398398
base = int(chunksize // ncols)
@@ -617,7 +617,7 @@ def _make_frame(names=None):
617617
for i in [6, 7]:
618618
msg = 'len of {i}, but only 5 lines in file'.format(i=i)
619619
with pytest.raises(ParserError, match=msg):
620-
read_csv(path, header=lrange(i), index_col=0)
620+
read_csv(path, header=list(range(i)), index_col=0)
621621

622622
# write with cols
623623
msg = 'cannot specify cols with a MultiIndex'
@@ -695,8 +695,9 @@ def create_cols(name):
695695

696696
def test_to_csv_dups_cols(self):
697697

698-
df = DataFrame(np.random.randn(1000, 30), columns=lrange(
699-
15) + lrange(15), dtype='float64')
698+
df = DataFrame(np.random.randn(1000, 30),
699+
columns=list(range(15)) + list(range(15)),
700+
dtype='float64')
700701

701702
with ensure_clean() as filename:
702703
df.to_csv(filename) # single dtype, fine
@@ -706,10 +707,10 @@ def test_to_csv_dups_cols(self):
706707

707708
df_float = DataFrame(np.random.randn(1000, 3), dtype='float64')
708709
df_int = DataFrame(np.random.randn(1000, 3), dtype='int64')
709-
df_bool = DataFrame(True, index=df_float.index, columns=lrange(3))
710-
df_object = DataFrame('foo', index=df_float.index, columns=lrange(3))
710+
df_bool = DataFrame(True, index=df_float.index, columns=range(3))
711+
df_object = DataFrame('foo', index=df_float.index, columns=range(3))
711712
df_dt = DataFrame(Timestamp('20010101'),
712-
index=df_float.index, columns=lrange(3))
713+
index=df_float.index, columns=range(3))
713714
df = pd.concat([df_float, df_int, df_bool, df_object,
714715
df_dt], axis=1, ignore_index=True)
715716

@@ -746,7 +747,7 @@ def test_to_csv_dups_cols(self):
746747

747748
def test_to_csv_chunking(self):
748749

749-
aa = DataFrame({'A': lrange(100000)})
750+
aa = DataFrame({'A': range(100000)})
750751
aa['B'] = aa.A + 1.0
751752
aa['C'] = aa.A + 2.0
752753
aa['D'] = aa.A + 3.0

pandas/tests/indexes/datetimes/test_datetime.py

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

7-
from pandas.compat import lrange
8-
97
import pandas as pd
108
from pandas import (
119
DataFrame, DatetimeIndex, Index, Timestamp, date_range, offsets)
@@ -102,7 +100,7 @@ def test_stringified_slice_with_tz(self):
102100
# GH#2658
103101
start = '2013-01-07'
104102
idx = date_range(start=start, freq="1d", periods=10, tz='US/Eastern')
105-
df = DataFrame(lrange(10), index=idx)
103+
df = DataFrame(np.arange(10), index=idx)
106104
df["2013-01-14 23:44:34.437768-05:00":] # no exception here
107105

108106
def test_append_join_nondatetimeindex(self):

pandas/tests/io/formats/test_to_html.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import numpy as np
66
import pytest
77

8-
from pandas.compat import lrange
9-
108
import pandas as pd
119
from pandas import DataFrame, Index, MultiIndex, option_context
1210
from pandas.util import testing as tm
@@ -51,7 +49,7 @@ def biggie_df_fixture(request):
5149
if request.param == 'mixed':
5250
df = DataFrame({'A': np.random.randn(200),
5351
'B': tm.makeStringIndex(200)},
54-
index=lrange(200))
52+
index=np.arange(200))
5553
df.loc[:20, 'A'] = np.nan
5654
df.loc[:20, 'B'] = np.nan
5755
return df
@@ -177,7 +175,7 @@ def test_to_html_multiindex_odd_even_truncate(max_rows, expected, datapath):
177175
@pytest.mark.parametrize('df,formatters,expected', [
178176
(DataFrame(
179177
[[0, 1], [2, 3], [4, 5], [6, 7]],
180-
columns=['foo', None], index=lrange(4)),
178+
columns=['foo', None], index=np.arange(4)),
181179
{'__index__': lambda x: 'abcd' [x]},
182180
'index_formatter'),
183181
@@ -303,13 +301,13 @@ def test_to_html_columns_arg():
303301

304302
@pytest.mark.parametrize('columns,justify,expected', [
305303
(MultiIndex.from_tuples(
306-
list(zip(np.arange(2).repeat(2), np.mod(lrange(4), 2))),
304+
list(zip(np.arange(2).repeat(2), np.mod(range(4), 2))),
307305
names=['CL0', 'CL1']),
308306
'left',
309307
'multiindex_1'),
310308
311309
(MultiIndex.from_tuples(
312-
list(zip(range(4), np.mod(lrange(4), 2)))),
310+
list(zip(range(4), np.mod(range(4), 2)))),
313311
'right',
314312
'multiindex_2')
315313
])

pandas/tests/io/json/test_pandas.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88
import pytest
99

10-
from pandas.compat import is_platform_32bit, lrange
10+
from pandas.compat import is_platform_32bit
1111
import pandas.util._test_decorators as td
1212

1313
import pandas as pd
@@ -647,7 +647,7 @@ def _check_all_orients(series, dtype=None, check_index_type=True):
647647
_check_all_orients(self.ts)
648648

649649
# dtype
650-
s = Series(lrange(6), index=['a', 'b', 'c', 'd', 'e', 'f'])
650+
s = Series(range(6), index=['a', 'b', 'c', 'd', 'e', 'f'])
651651
_check_all_orients(Series(s, dtype=np.float64), dtype=np.float64)
652652
_check_all_orients(Series(s, dtype=np.int), dtype=np.int)
653653

@@ -677,8 +677,8 @@ def test_frame_from_json_precise_float(self):
677677

678678
def test_typ(self):
679679

680-
s = Series(lrange(6), index=['a', 'b', 'c',
681-
'd', 'e', 'f'], dtype='int64')
680+
s = Series(range(6), index=['a', 'b', 'c',
681+
'd', 'e', 'f'], dtype='int64')
682682
result = read_json(s.to_json(), typ=None)
683683
assert_series_equal(result, s)
684684

@@ -841,7 +841,7 @@ def test_weird_nested_json(self):
841841
def test_doc_example(self):
842842
dfj2 = DataFrame(np.random.randn(5, 2), columns=list('AB'))
843843
dfj2['date'] = Timestamp('20130101')
844-
dfj2['ints'] = lrange(5)
844+
dfj2['ints'] = range(5)
845845
dfj2['bools'] = True
846846
dfj2.index = pd.date_range('20130101', periods=5)
847847

0 commit comments

Comments
 (0)