Skip to content

CLN: remove compat.lrange, part II #26289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import pandas._libs.parsers as parsers
from pandas._libs.tslibs import parsing
import pandas.compat as compat
from pandas.compat import lrange, lzip
from pandas.compat import lzip
from pandas.errors import (
AbstractMethodError, EmptyDataError, ParserError, ParserWarning)
from pandas.util._decorators import Appender
Expand Down Expand Up @@ -1105,7 +1105,7 @@ def _clean_options(self, options, engine):
# c-engine, so only need for python parsers
if engine != 'c':
if is_integer(skiprows):
skiprows = lrange(skiprows)
skiprows = list(range(skiprows))
if skiprows is None:
skiprows = set()
elif not callable(skiprows):
Expand Down Expand Up @@ -1883,7 +1883,7 @@ def __init__(self, src, **kwds):
self.names = ['{prefix}{i}'.format(prefix=self.prefix, i=i)
for i in range(self._reader.table_width)]
else:
self.names = lrange(self._reader.table_width)
self.names = list(range(self._reader.table_width))

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

if len(self.names) > len(usecols):
Expand Down Expand Up @@ -2607,7 +2607,7 @@ def _infer_columns(self):
# validate that column indices in usecols are not out of bounds
if self.usecols_dtype == 'integer':
for col in columns:
indices = lrange(len(col))
indices = range(len(col))
_validate_usecols_names(self.usecols, indices)

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

if not names:
if self.prefix:
columns = [['{prefix}{idx}'.format(
prefix=self.prefix, idx=i) for i in range(ncols)]]
else:
columns = [lrange(ncols)]
columns = [list(range(ncols))]
columns = self._handle_usecols(columns, columns[0])
else:
if self.usecols is None or len(names) >= num_original_columns:
Expand Down Expand Up @@ -3007,7 +3007,7 @@ def _get_index_name(self, columns):
if next_line is not None:
if len(next_line) == len(line) + self.num_original_columns:
# column and index names on diff rows
self.index_col = lrange(len(line))
self.index_col = list(range(len(line)))
self.buf = self.buf[1:]

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

index_name = None

Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/frame/test_query_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import numpy as np
import pytest

from pandas.compat import lrange
import pandas.util._test_decorators as td

import pandas as pd
Expand Down Expand Up @@ -460,8 +459,8 @@ def test_date_query_with_non_date(self):

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

Expand Down
27 changes: 14 additions & 13 deletions pandas/tests/frame/test_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import pytest

from pandas.compat import lmap, lrange
from pandas.compat import lmap
from pandas.errors import ParserError

import pandas as pd
Expand Down Expand Up @@ -69,8 +69,8 @@ def test_to_csv_from_csv1(self):
assert_almost_equal(self.tsframe.values, recons.values)

# corner case
dm = DataFrame({'s1': Series(lrange(3), lrange(3)),
's2': Series(lrange(2), lrange(2))})
dm = DataFrame({'s1': Series(range(3), index=np.arange(3)),
's2': Series(range(2), index=np.arange(2))})
dm.to_csv(path)

recons = self.read_csv(path)
Expand Down Expand Up @@ -259,8 +259,8 @@ def _do_test(df, r_dtype=None, c_dtype=None,
kwargs = dict(parse_dates=False)
if cnlvl:
if rnlvl is not None:
kwargs['index_col'] = lrange(rnlvl)
kwargs['header'] = lrange(cnlvl)
kwargs['index_col'] = list(range(rnlvl))
kwargs['header'] = list(range(cnlvl))

with ensure_clean('__tmp_to_csv_moar__') as path:
df.to_csv(path, encoding='utf8',
Expand Down Expand Up @@ -392,7 +392,7 @@ def _to_uni(x):
df.columns = cols
_do_test(df, dupe_col=True)

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

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

def test_to_csv_dups_cols(self):

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

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

df_float = DataFrame(np.random.randn(1000, 3), dtype='float64')
df_int = DataFrame(np.random.randn(1000, 3), dtype='int64')
df_bool = DataFrame(True, index=df_float.index, columns=lrange(3))
df_object = DataFrame('foo', index=df_float.index, columns=lrange(3))
df_bool = DataFrame(True, index=df_float.index, columns=range(3))
df_object = DataFrame('foo', index=df_float.index, columns=range(3))
df_dt = DataFrame(Timestamp('20010101'),
index=df_float.index, columns=lrange(3))
index=df_float.index, columns=range(3))
df = pd.concat([df_float, df_int, df_bool, df_object,
df_dt], axis=1, ignore_index=True)

Expand Down Expand Up @@ -746,7 +747,7 @@ def test_to_csv_dups_cols(self):

def test_to_csv_chunking(self):

aa = DataFrame({'A': lrange(100000)})
aa = DataFrame({'A': range(100000)})
aa['B'] = aa.A + 1.0
aa['C'] = aa.A + 2.0
aa['D'] = aa.A + 3.0
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/indexes/datetimes/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import numpy as np
import pytest

from pandas.compat import lrange

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

def test_append_join_nondatetimeindex(self):
Expand Down
10 changes: 4 additions & 6 deletions pandas/tests/io/formats/test_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import numpy as np
import pytest

from pandas.compat import lrange

import pandas as pd
from pandas import DataFrame, Index, MultiIndex, option_context
from pandas.util import testing as tm
Expand Down Expand Up @@ -51,7 +49,7 @@ def biggie_df_fixture(request):
if request.param == 'mixed':
df = DataFrame({'A': np.random.randn(200),
'B': tm.makeStringIndex(200)},
index=lrange(200))
index=np.arange(200))
df.loc[:20, 'A'] = np.nan
df.loc[:20, 'B'] = np.nan
return df
Expand Down Expand Up @@ -177,7 +175,7 @@ def test_to_html_multiindex_odd_even_truncate(max_rows, expected, datapath):
@pytest.mark.parametrize('df,formatters,expected', [
(DataFrame(
[[0, 1], [2, 3], [4, 5], [6, 7]],
columns=['foo', None], index=lrange(4)),
columns=['foo', None], index=np.arange(4)),
{'__index__': lambda x: 'abcd' [x]},
'index_formatter'),

Expand Down Expand Up @@ -303,13 +301,13 @@ def test_to_html_columns_arg():

@pytest.mark.parametrize('columns,justify,expected', [
(MultiIndex.from_tuples(
list(zip(np.arange(2).repeat(2), np.mod(lrange(4), 2))),
list(zip(np.arange(2).repeat(2), np.mod(range(4), 2))),
names=['CL0', 'CL1']),
'left',
'multiindex_1'),

(MultiIndex.from_tuples(
list(zip(range(4), np.mod(lrange(4), 2)))),
list(zip(range(4), np.mod(range(4), 2)))),
'right',
'multiindex_2')
])
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
import pytest

from pandas.compat import is_platform_32bit, lrange
from pandas.compat import is_platform_32bit
import pandas.util._test_decorators as td

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

# dtype
s = Series(lrange(6), index=['a', 'b', 'c', 'd', 'e', 'f'])
s = Series(range(6), index=['a', 'b', 'c', 'd', 'e', 'f'])
_check_all_orients(Series(s, dtype=np.float64), dtype=np.float64)
_check_all_orients(Series(s, dtype=np.int), dtype=np.int)

Expand Down Expand Up @@ -677,8 +677,8 @@ def test_frame_from_json_precise_float(self):

def test_typ(self):

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

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

Expand Down
Loading