Skip to content

CLN: remove compat.iterkeys #26081

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 2 commits 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
6 changes: 1 addition & 5 deletions pandas/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Key items to import for compatible code:
* lists: lrange(), lmap(), lzip(), lfilter()
* iterable method compatibility: iterkeys, itervalues
* 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,10 +41,6 @@ def lfilter(*args, **kwargs):
return list(filter(*args, **kwargs))


def iterkeys(obj, **kw):
return iter(obj.keys(**kw))


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

Expand Down
6 changes: 3 additions & 3 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def nested_renaming_depr(level=4):
else:
# deprecation of renaming keys
# GH 15931
keys = list(compat.iterkeys(arg))
keys = list(arg.keys())
if (isinstance(obj, ABCDataFrame) and
len(obj.columns.intersection(keys)) != len(keys)):
nested_renaming_depr()
Expand Down Expand Up @@ -437,7 +437,7 @@ def _agg(arg, func):
return result

# set the final keys
keys = list(compat.iterkeys(arg))
keys = list(arg.keys())
result = OrderedDict()

# nested renamer
Expand All @@ -449,7 +449,7 @@ def _agg(arg, func):
result, results = OrderedDict(), result
for r in results:
result.update(r)
keys = list(compat.iterkeys(result))
keys = list(result.keys())

else:

Expand Down
6 changes: 3 additions & 3 deletions pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
ensure_object, is_categorical_dtype, is_datetime64_dtype)

from pandas import (
Categorical, DatetimeIndex, NaT, Timestamp, compat, concat, isna,
to_datetime, to_timedelta)
Categorical, DatetimeIndex, NaT, Timestamp, concat, isna, to_datetime,
to_timedelta)
from pandas.core.base import StringMixin
from pandas.core.frame import DataFrame
from pandas.core.series import Series
Expand Down Expand Up @@ -1700,7 +1700,7 @@ def _do_convert_categoricals(self, data, value_label_dict, lbllist,
"""
Converts categorical columns to Categorical type.
"""
value_labels = list(compat.iterkeys(value_label_dict))
value_labels = list(value_label_dict.keys())
cat_converted_data = []
for col, label in zip(data, lbllist):
if label in value_labels:
Expand Down
5 changes: 1 addition & 4 deletions pandas/tests/io/test_stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import numpy as np
import pytest

from pandas.compat import iterkeys

from pandas.core.dtypes.common import is_categorical_dtype

import pandas as pd
Expand Down Expand Up @@ -755,8 +753,7 @@ def test_missing_value_generator(self):
def test_missing_value_conversion(self, file):
columns = ['int8_', 'int16_', 'int32_', 'float32_', 'float64_']
smv = StataMissingValue(101)
keys = [key for key in iterkeys(smv.MISSING_VALUES)]
keys.sort()
keys = sorted(smv.MISSING_VALUES.keys())
data = []
for i in range(27):
row = [StataMissingValue(keys[i + (j * 27)]) for j in range(5)]
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import builtins
import re

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


class TestBuiltinIterators(object):
Expand Down Expand Up @@ -53,7 +52,6 @@ def test_lzip(self):

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


def test_re_type():
Expand Down