Skip to content

Commit 53d8575

Browse files
topper-123yhaque1213
authored andcommitted
CLN: remove compat.itervalues (pandas-dev#26099)
1 parent f29c74d commit 53d8575

File tree

10 files changed

+14
-30
lines changed

10 files changed

+14
-30
lines changed

pandas/compat/__init__.py

-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
77
Key items to import for compatible code:
88
* lists: lrange(), lmap(), lzip(), lfilter()
9-
* iterable method compatibility: itervalues
10-
* Uses the original method if available, otherwise uses items, keys, values.
119
* add_metaclass(metaclass) - class decorator that recreates class with with the
1210
given metaclass instead (and avoids intermediary class creation)
1311
@@ -41,9 +39,6 @@ def lfilter(*args, **kwargs):
4139
return list(filter(*args, **kwargs))
4240

4341

44-
def itervalues(obj, **kw):
45-
return iter(obj.values(**kw))
46-
4742
# ----------------------------------------------------------------------------
4843
# functions largely based / taken from the six module
4944

pandas/core/base.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import numpy as np
1010

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

494493
def is_any_series():
495494
# return a boolean if we have *any* nested series
496-
return any(isinstance(r, ABCSeries)
497-
for r in compat.itervalues(result))
495+
return any(isinstance(r, ABCSeries) for r in result.values())
498496

499497
def is_any_frame():
500498
# return a boolean if we have *any* nested series
501499
return any(isinstance(r, ABCDataFrame)
502-
for r in compat.itervalues(result))
500+
for r in result.values())
503501

504502
if isinstance(result, list):
505503
return concat(result, keys=keys, axis=1, sort=True), True

pandas/core/dtypes/concat.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
ABCDatetimeArray, ABCDatetimeIndex, ABCIndexClass, ABCPeriodIndex,
1515
ABCRangeIndex, ABCSparseDataFrame, ABCTimedeltaIndex)
1616

17-
from pandas import compat
18-
1917

2018
def get_dtype_kinds(l):
2119
"""
@@ -69,7 +67,7 @@ def _get_series_result_type(result, objs=None):
6967
if isinstance(result, dict):
7068
# concat Series with axis 1
7169
if all(isinstance(c, (SparseSeries, SparseDataFrame))
72-
for c in compat.itervalues(result)):
70+
for c in result.values()):
7371
return SparseDataFrame
7472
else:
7573
return DataFrame

pandas/core/groupby/generic.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import numpy as np
1616

1717
from pandas._libs import Timestamp, lib
18-
import pandas.compat as compat
1918
from pandas.compat import lzip
2019
from pandas.errors import AbstractMethodError
2120
from pandas.util._decorators import Appender, Substitution
@@ -850,7 +849,7 @@ def _aggregate_multiple_funcs(self, arg, _level):
850849
obj._selection = name
851850
results[name] = obj.aggregate(func)
852851

853-
if any(isinstance(x, DataFrame) for x in compat.itervalues(results)):
852+
if any(isinstance(x, DataFrame) for x in results.values()):
854853
# let higher level handle
855854
if _level:
856855
return results

pandas/core/nanops.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from pandas._config import get_option
1010

1111
from pandas._libs import iNaT, lib, tslibs
12-
import pandas.compat as compat
1312

1413
from pandas.core.dtypes.cast import _int64_max, maybe_upcast_putmask
1514
from pandas.core.dtypes.common import (
@@ -68,7 +67,7 @@ def check(self, obj):
6867
def __call__(self, f):
6968
@functools.wraps(f)
7069
def _f(*args, **kwargs):
71-
obj_iter = itertools.chain(args, compat.itervalues(kwargs))
70+
obj_iter = itertools.chain(args, kwargs.values())
7271
if any(self.check(obj) for obj in obj_iter):
7372
msg = 'reduction operation {name!r} not allowed for this dtype'
7473
raise TypeError(msg.format(name=f.__name__.replace('nan', '')))

pandas/core/panel.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import numpy as np
88

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

11851184
# have a dict, so top-level is +1 dim
11861185
if ndim != 0:

pandas/io/json/normalize.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from pandas._libs.writers import convert_json_to_lines
1010

11-
from pandas import DataFrame, compat
11+
from pandas import DataFrame
1212

1313

1414
def _convert_to_line_delimits(s):
@@ -198,8 +198,7 @@ def _pull_field(js, spec):
198198
data = [data]
199199

200200
if record_path is None:
201-
if any([isinstance(x, dict)
202-
for x in compat.itervalues(y)] for y in data):
201+
if any([isinstance(x, dict) for x in y.values()] for y in data):
203202
# naive normalization, this is idempotent for flat records
204203
# and potentially will inflate the data considerably for
205204
# deeply nested structures:

pandas/io/parsers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ def read(self, nrows=None):
11541154
if index is None:
11551155
if col_dict:
11561156
# Any column is actually fine:
1157-
new_rows = len(next(compat.itervalues(col_dict)))
1157+
new_rows = len(next(iter(col_dict.values())))
11581158
index = RangeIndex(self._currow, self._currow + new_rows)
11591159
else:
11601160
new_rows = 0

pandas/tests/io/test_packers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import pandas
1515
from pandas import (
1616
Categorical, DataFrame, Index, Interval, MultiIndex, NaT, Period, Series,
17-
Timestamp, bdate_range, compat, date_range, period_range)
17+
Timestamp, bdate_range, date_range, period_range)
1818
import pandas.util.testing as tm
1919
from pandas.util.testing import (
2020
assert_categorical_equal, assert_frame_equal, assert_index_equal,
@@ -818,12 +818,12 @@ def setup_method(self, method):
818818
def test_utf(self):
819819
# GH10581
820820
for encoding in self.utf_encodings:
821-
for frame in compat.itervalues(self.frame):
821+
for frame in self.frame.values():
822822
result = self.encode_decode(frame, encoding=encoding)
823823
assert_frame_equal(result, frame)
824824

825825
def test_default_encoding(self):
826-
for frame in compat.itervalues(self.frame):
826+
for frame in self.frame.values():
827827
result = frame.to_msgpack()
828828
expected = frame.to_msgpack(encoding='utf8')
829829
assert result == expected

pandas/tests/test_compat.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import builtins
66
import re
77

8-
from pandas.compat import itervalues, lfilter, lmap, lrange, lzip, re_type
8+
from pandas.compat import lfilter, lmap, lrange, lzip, re_type
99

1010

1111
class TestBuiltinIterators(object):
@@ -50,9 +50,6 @@ def test_lzip(self):
5050
lengths = 10,
5151
self.check_results(results, expecteds, lengths)
5252

53-
def test_dict_iterators(self):
54-
assert next(itervalues({1: 2})) == 2
55-
5653

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

0 commit comments

Comments
 (0)