Skip to content

Commit

Permalink
CLN: remove compat.lrange (#26396)
Browse files Browse the repository at this point in the history
  • Loading branch information
topper-123 authored and jreback committed May 15, 2019
1 parent 3b24fb6 commit a738223
Show file tree
Hide file tree
Showing 51 changed files with 213 additions and 288 deletions.
8 changes: 0 additions & 8 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
Cross-compatible functions for different versions of Python.
Key items to import for compatible code:
* lists: lrange()
Other items:
* platform checker
"""
Expand All @@ -19,11 +16,6 @@
PYPY = platform.python_implementation() == 'PyPy'


# list-producing versions of the major Python iterating functions
def lrange(*args, **kwargs):
return list(range(*args, **kwargs))


# ----------------------------------------------------------------------------
# functions largely based / taken from the six module

Expand Down
3 changes: 1 addition & 2 deletions pandas/plotting/_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from pandas._libs import lib, tslibs
from pandas._libs.tslibs import resolution
from pandas._libs.tslibs.frequencies import FreqGroup, get_freq
from pandas.compat import lrange

from pandas.core.dtypes.common import (
is_datetime64_ns_dtype, is_float, is_float_dtype, is_integer,
Expand Down Expand Up @@ -1029,7 +1028,7 @@ def __call__(self):
base = self.base
(d, m) = divmod(vmin, base)
vmin = (d + 1) * base
locs = lrange(vmin, vmax + 1, base)
locs = list(range(vmin, vmax + 1, base))
return locs

def autoscale(self):
Expand Down
5 changes: 2 additions & 3 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from pandas._config import get_option

from pandas.compat import lrange
from pandas.errors import AbstractMethodError
from pandas.util._decorators import Appender, cache_readonly

Expand Down Expand Up @@ -583,9 +582,9 @@ def _get_xticks(self, convert_period=False):
x = self.data.index._mpl_repr()
else:
self._need_to_set_index = True
x = lrange(len(index))
x = list(range(len(index)))
else:
x = lrange(len(index))
x = list(range(len(index)))

return x

Expand Down
9 changes: 4 additions & 5 deletions pandas/plotting/_misc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# being a bit too dynamic
import numpy as np

from pandas.compat import lrange
from pandas.util._decorators import deprecate_kwarg

from pandas.core.dtypes.missing import notna
Expand Down Expand Up @@ -81,8 +80,8 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
rdelta_ext = (rmax_ - rmin_) * range_padding / 2.
boundaries_list.append((rmin_ - rdelta_ext, rmax_ + rdelta_ext))

for i, a in zip(lrange(n), df.columns):
for j, b in zip(lrange(n), df.columns):
for i, a in enumerate(df.columns):
for j, b in enumerate(df.columns):
ax = axes[i, j]

if i == j:
Expand Down Expand Up @@ -420,7 +419,7 @@ def bootstrap_plot(series, fig=None, size=50, samples=500, **kwds):
for sampling in samplings])
if fig is None:
fig = plt.figure()
x = lrange(samples)
x = list(range(samples))
axes = []
ax1 = fig.add_subplot(2, 3, 1)
ax1.set_xlabel("Sample")
Expand Down Expand Up @@ -532,7 +531,7 @@ def parallel_coordinates(frame, class_column, cols=None, ax=None, color=None,
raise ValueError('Length of xticks must match number of columns')
x = xticks
else:
x = lrange(ncols)
x = list(range(ncols))

if ax is None:
ax = plt.gca()
Expand Down
4 changes: 1 addition & 3 deletions pandas/plotting/_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import numpy as np

from pandas.compat import lrange

from pandas.core.dtypes.common import is_list_like


Expand Down Expand Up @@ -49,7 +47,7 @@ def random_color(column):
rs = com.random_state(column)
return rs.rand(3).tolist()

colors = [random_color(num) for num in lrange(num_colors)]
colors = [random_color(num) for num in range(num_colors)]
else:
raise ValueError("color_type must be either 'default' or 'random'")

Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/arrays/categorical/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import numpy as np
import pytest

from pandas.compat import lrange

from pandas.core.dtypes.dtypes import CategoricalDtype

from pandas import Categorical, Index, isna
Expand All @@ -16,7 +14,7 @@ class TestCategoricalMissing:
def test_na_flags_int_categories(self):
# #1457

categories = lrange(10)
categories = list(range(10))
labels = np.random.randint(0, 10, 20)
labels[::5] = -1

Expand Down
26 changes: 12 additions & 14 deletions pandas/tests/frame/test_duplicates.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
import pytest

from pandas.compat import lrange

from pandas import DataFrame, Series
import pandas.util.testing as tm

Expand Down Expand Up @@ -88,8 +86,8 @@ def test_drop_duplicates():
'B': ['one', 'one', 'two', 'two',
'two', 'two', 'one', 'two'],
'C': [1, 1, 2, 2, 2, 2, 1, 2],
'D': lrange(8)})

'D': range(8),
})
# single column
result = df.drop_duplicates('AAA')
expected = df[:2]
Expand Down Expand Up @@ -211,8 +209,8 @@ def test_drop_duplicates_for_take_all():
'B': ['one', 'one', 'two', 'two',
'two', 'two', 'one', 'two'],
'C': [1, 1, 2, 2, 2, 2, 1, 2],
'D': lrange(8)})

'D': range(8),
})
# single column
result = df.drop_duplicates('AAA')
expected = df.iloc[[0, 1, 2, 6]]
Expand Down Expand Up @@ -246,8 +244,8 @@ def test_drop_duplicates_tuple():
'B': ['one', 'one', 'two', 'two',
'two', 'two', 'one', 'two'],
'C': [1, 1, 2, 2, 2, 2, 1, 2],
'D': lrange(8)})

'D': range(8),
})
# single column
result = df.drop_duplicates(('AA', 'AB'))
expected = df[:2]
Expand Down Expand Up @@ -292,8 +290,8 @@ def test_drop_duplicates_NA():
'B': ['one', 'one', 'two', 'two',
'two', 'two', 'one', 'two'],
'C': [1.0, np.nan, np.nan, np.nan, 1., 1., 1, 1.],
'D': lrange(8)})

'D': range(8),
})
# single column
result = df.drop_duplicates('A')
expected = df.loc[[0, 2, 3]]
Expand Down Expand Up @@ -327,8 +325,8 @@ def test_drop_duplicates_NA():
'B': ['one', 'one', 'two', 'two',
'two', 'two', 'one', 'two'],
'C': [1.0, np.nan, np.nan, np.nan, 1., 1., 1, 1.],
'D': lrange(8)})

'D': range(8),
})
# single column
result = df.drop_duplicates('C')
expected = df[:2]
Expand Down Expand Up @@ -398,8 +396,8 @@ def test_drop_duplicates_inplace():
'B': ['one', 'one', 'two', 'two',
'two', 'two', 'one', 'two'],
'C': [1, 1, 2, 2, 2, 2, 1, 2],
'D': lrange(8)})

'D': range(8),
})
# single column
df = orig.copy()
df.drop_duplicates('A', inplace=True)
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/indexes/datetimes/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import pytz

from pandas._libs.tslibs import conversion, timezones
from pandas.compat import lrange
import pandas.util._test_decorators as td

import pandas as pd
Expand Down Expand Up @@ -958,7 +957,7 @@ def test_dti_with_timezone_repr(self, tzstr):
def test_dti_take_dont_lose_meta(self, tzstr):
rng = date_range('1/1/2000', periods=20, tz=tzstr)

result = rng.take(lrange(5))
result = rng.take(range(5))
assert result.tz == rng.tz
assert result.freq == rng.freq

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

from pandas.compat import lrange
from pandas.compat.numpy import _np_version_under1p17

import pandas as pd
Expand Down Expand Up @@ -32,8 +31,8 @@ def test_groupby(idx):


def test_truncate():
major_axis = Index(lrange(4))
minor_axis = Index(lrange(2))
major_axis = Index(list(range(4)))
minor_axis = Index(list(range(2)))

major_codes = np.array([0, 0, 1, 2, 3, 3])
minor_codes = np.array([0, 1, 0, 1, 0, 1])
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/indexes/multi/test_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pytest

from pandas._libs.tslib import Timestamp
from pandas.compat import lrange

from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike

Expand Down Expand Up @@ -383,7 +382,7 @@ def test_from_product_empty_two_levels(first, second):
def test_from_product_empty_three_levels(N):
# GH12258
names = ['A', 'B', 'C']
lvl2 = lrange(N)
lvl2 = list(range(N))
result = MultiIndex.from_product([[], lvl2, []], names=names)
expected = MultiIndex(levels=[[], lvl2, []],
codes=[[], [], []], names=names)
Expand Down
15 changes: 8 additions & 7 deletions pandas/tests/indexes/multi/test_drop.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
import pytest

from pandas.compat import lrange
from pandas.errors import PerformanceWarning

import pandas as pd
Expand Down Expand Up @@ -73,9 +72,10 @@ def test_droplevel_with_names(idx):
assert dropped.name == 'second'

index = MultiIndex(
levels=[Index(lrange(4)), Index(lrange(4)), Index(lrange(4))],
codes=[np.array([0, 0, 1, 2, 2, 2, 3, 3]), np.array(
[0, 1, 0, 0, 0, 1, 0, 1]), np.array([1, 0, 1, 1, 0, 0, 1, 0])],
levels=[Index(range(4)), Index(range(4)), Index(range(4))],
codes=[np.array([0, 0, 1, 2, 2, 2, 3, 3]),
np.array([0, 1, 0, 0, 0, 1, 0, 1]),
np.array([1, 0, 1, 1, 0, 0, 1, 0])],
names=['one', 'two', 'three'])
dropped = index.droplevel(0)
assert dropped.names == ('two', 'three')
Expand All @@ -87,9 +87,10 @@ def test_droplevel_with_names(idx):

def test_droplevel_list():
index = MultiIndex(
levels=[Index(lrange(4)), Index(lrange(4)), Index(lrange(4))],
codes=[np.array([0, 0, 1, 2, 2, 2, 3, 3]), np.array(
[0, 1, 0, 0, 0, 1, 0, 1]), np.array([1, 0, 1, 1, 0, 0, 1, 0])],
levels=[Index(range(4)), Index(range(4)), Index(range(4))],
codes=[np.array([0, 0, 1, 2, 2, 2, 3, 3]),
np.array([0, 1, 0, 0, 0, 1, 0, 1]),
np.array([1, 0, 1, 1, 0, 0, 1, 0])],
names=['one', 'two', 'three'])

dropped = index[:2].droplevel(['three', 'one'])
Expand Down
20 changes: 11 additions & 9 deletions pandas/tests/indexes/multi/test_equivalence.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
import pytest

from pandas.compat import lrange

import pandas as pd
from pandas import Index, MultiIndex, Series
import pandas.util.testing as tm
Expand Down Expand Up @@ -96,17 +94,21 @@ def test_equals_multi(idx):
assert not idx.equals(idx[-1])

# different number of levels
index = MultiIndex(levels=[Index(lrange(4)), Index(lrange(4)), Index(
lrange(4))], codes=[np.array([0, 0, 1, 2, 2, 2, 3, 3]), np.array(
[0, 1, 0, 0, 0, 1, 0, 1]), np.array([1, 0, 1, 1, 0, 0, 1, 0])])
index = MultiIndex(levels=[Index(list(range(4))),
Index(list(range(4))),
Index(list(range(4)))],
codes=[np.array([0, 0, 1, 2, 2, 2, 3, 3]),
np.array([0, 1, 0, 0, 0, 1, 0, 1]),
np.array([1, 0, 1, 1, 0, 0, 1, 0])],
)

index2 = MultiIndex(levels=index.levels[:-1], codes=index.codes[:-1])
assert not index.equals(index2)
assert not index.equal_levels(index2)

# levels are different
major_axis = Index(lrange(4))
minor_axis = Index(lrange(2))
major_axis = Index(list(range(4)))
minor_axis = Index(list(range(2)))

major_codes = np.array([0, 0, 1, 2, 2, 3])
minor_codes = np.array([0, 1, 0, 0, 1, 0])
Expand Down Expand Up @@ -178,14 +180,14 @@ def test_is_():
mi2.set_names(["E", "F"], inplace=True)
assert mi.is_(mi2)
# levels are inherent properties, they change identity
mi3 = mi2.set_levels([lrange(10), lrange(10)])
mi3 = mi2.set_levels([list(range(10)), list(range(10))])
assert not mi3.is_(mi2)
# shouldn't change
assert mi2.is_(mi)
mi4 = mi3.view()

# GH 17464 - Remove duplicate MultiIndex levels
mi4.set_levels([lrange(10), lrange(10)], inplace=True)
mi4.set_levels([list(range(10)), list(range(10))], inplace=True)
assert not mi4.is_(mi3)
mi5 = mi.view()
mi5.set_levels(mi5.levels, inplace=True)
Expand Down
Loading

0 comments on commit a738223

Please sign in to comment.