Skip to content

CLN: remove compat.itervalues #26099

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
Apr 15, 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
5 changes: 0 additions & 5 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
Key items to import for compatible code:
* lists: lrange(), lmap(), lzip(), lfilter()
* iterable method compatibility: itervalues
* Uses the original method if available, otherwise uses items, keys, values.
* add_metaclass(metaclass) - class decorator that recreates class with with the
given metaclass instead (and avoids intermediary class creation)
Expand Down Expand Up @@ -41,9 +39,6 @@ def lfilter(*args, **kwargs):
return list(filter(*args, **kwargs))


def itervalues(obj, **kw):
return iter(obj.values(**kw))

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

Expand Down
8 changes: 3 additions & 5 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import numpy as np

import pandas._libs.lib as lib
import pandas.compat as compat
from pandas.compat import PYPY
from pandas.compat.numpy import function as nv
from pandas.errors import AbstractMethodError
Expand Down Expand Up @@ -362,7 +361,7 @@ def nested_renaming_depr(level=4):
# if we have a dict of any non-scalars
# eg. {'A' : ['mean']}, normalize all to
# be list-likes
if any(is_aggregator(x) for x in compat.itervalues(arg)):
if any(is_aggregator(x) for x in arg.values()):
new_arg = OrderedDict()
for k, v in arg.items():
if not isinstance(v, (tuple, list, dict)):
Expand Down Expand Up @@ -493,13 +492,12 @@ def _agg(arg, func):

def is_any_series():
# return a boolean if we have *any* nested series
return any(isinstance(r, ABCSeries)
for r in compat.itervalues(result))
return any(isinstance(r, ABCSeries) for r in result.values())

def is_any_frame():
# return a boolean if we have *any* nested series
return any(isinstance(r, ABCDataFrame)
for r in compat.itervalues(result))
for r in result.values())

if isinstance(result, list):
return concat(result, keys=keys, axis=1, sort=True), True
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/dtypes/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
ABCDatetimeArray, ABCDatetimeIndex, ABCIndexClass, ABCPeriodIndex,
ABCRangeIndex, ABCSparseDataFrame, ABCTimedeltaIndex)

from pandas import compat


def get_dtype_kinds(l):
"""
Expand Down Expand Up @@ -69,7 +67,7 @@ def _get_series_result_type(result, objs=None):
if isinstance(result, dict):
# concat Series with axis 1
if all(isinstance(c, (SparseSeries, SparseDataFrame))
for c in compat.itervalues(result)):
for c in result.values()):
return SparseDataFrame
else:
return DataFrame
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import numpy as np

from pandas._libs import Timestamp, lib
import pandas.compat as compat
from pandas.compat import lzip
from pandas.errors import AbstractMethodError
from pandas.util._decorators import Appender, Substitution
Expand Down Expand Up @@ -850,7 +849,7 @@ def _aggregate_multiple_funcs(self, arg, _level):
obj._selection = name
results[name] = obj.aggregate(func)

if any(isinstance(x, DataFrame) for x in compat.itervalues(results)):
if any(isinstance(x, DataFrame) for x in results.values()):
# let higher level handle
if _level:
return results
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pandas._config import get_option

from pandas._libs import iNaT, lib, tslibs
import pandas.compat as compat

from pandas.core.dtypes.cast import _int64_max, maybe_upcast_putmask
from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -68,7 +67,7 @@ def check(self, obj):
def __call__(self, f):
@functools.wraps(f)
def _f(*args, **kwargs):
obj_iter = itertools.chain(args, compat.itervalues(kwargs))
obj_iter = itertools.chain(args, kwargs.values())
if any(self.check(obj) for obj in obj_iter):
msg = 'reduction operation {name!r} not allowed for this dtype'
raise TypeError(msg.format(name=f.__name__.replace('nan', '')))
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import numpy as np

import pandas.compat as compat
from pandas.compat.numpy import function as nv
from pandas.util._decorators import Appender, Substitution, deprecate_kwarg
from pandas.util._validators import validate_axis_style_args
Expand Down Expand Up @@ -1180,7 +1179,7 @@ def _construct_return_type(self, result, axes=None):
# need to assume they are the same
if ndim is None:
if isinstance(result, dict):
ndim = getattr(list(compat.itervalues(result))[0], 'ndim', 0)
ndim = getattr(list(result.values())[0], 'ndim', 0)

# have a dict, so top-level is +1 dim
if ndim != 0:
Expand Down
5 changes: 2 additions & 3 deletions pandas/io/json/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from pandas._libs.writers import convert_json_to_lines

from pandas import DataFrame, compat
from pandas import DataFrame


def _convert_to_line_delimits(s):
Expand Down Expand Up @@ -198,8 +198,7 @@ def _pull_field(js, spec):
data = [data]

if record_path is None:
if any([isinstance(x, dict)
for x in compat.itervalues(y)] for y in data):
if any([isinstance(x, dict) for x in y.values()] for y in data):
# naive normalization, this is idempotent for flat records
# and potentially will inflate the data considerably for
# deeply nested structures:
Expand Down
2 changes: 1 addition & 1 deletion pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ def read(self, nrows=None):
if index is None:
if col_dict:
# Any column is actually fine:
new_rows = len(next(compat.itervalues(col_dict)))
new_rows = len(next(iter(col_dict.values())))
index = RangeIndex(self._currow, self._currow + new_rows)
else:
new_rows = 0
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/io/test_packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pandas
from pandas import (
Categorical, DataFrame, Index, Interval, MultiIndex, NaT, Period, Series,
Timestamp, bdate_range, compat, date_range, period_range)
Timestamp, bdate_range, date_range, period_range)
import pandas.util.testing as tm
from pandas.util.testing import (
assert_categorical_equal, assert_frame_equal, assert_index_equal,
Expand Down Expand Up @@ -818,12 +818,12 @@ def setup_method(self, method):
def test_utf(self):
# GH10581
for encoding in self.utf_encodings:
for frame in compat.itervalues(self.frame):
for frame in self.frame.values():
result = self.encode_decode(frame, encoding=encoding)
assert_frame_equal(result, frame)

def test_default_encoding(self):
for frame in compat.itervalues(self.frame):
for frame in self.frame.values():
result = frame.to_msgpack()
expected = frame.to_msgpack(encoding='utf8')
assert result == expected
Expand Down
5 changes: 1 addition & 4 deletions pandas/tests/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import builtins
import re

from pandas.compat import itervalues, lfilter, lmap, lrange, lzip, re_type
from pandas.compat import lfilter, lmap, lrange, lzip, re_type


class TestBuiltinIterators(object):
Expand Down Expand Up @@ -50,9 +50,6 @@ def test_lzip(self):
lengths = 10,
self.check_results(results, expecteds, lengths)

def test_dict_iterators(self):
assert next(itervalues({1: 2})) == 2


def test_re_type():
assert isinstance(re.compile(''), re_type)