From a17ddab941b43c8fa6afdb7d9435fd217f9d60c9 Mon Sep 17 00:00:00 2001 From: Nate Yoder Date: Tue, 29 Nov 2016 06:45:19 -0800 Subject: [PATCH] Fix unused import and docstrings per pep8radius docformatter; change other uses of assert_index_equal to testing instead os self --- pandas/core/categorical.py | 4 ++-- pandas/indexes/base.py | 4 ++-- pandas/indexes/category.py | 4 ++-- pandas/tests/indexes/test_base.py | 16 ++++++++-------- pandas/tseries/base.py | 1 - pandas/tseries/tests/test_timedeltas.py | 2 +- pandas/tseries/tests/test_timeseries.py | 2 +- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pandas/core/categorical.py b/pandas/core/categorical.py index 4f72f6d59c7a8..5124dc44e2fc8 100644 --- a/pandas/core/categorical.py +++ b/pandas/core/categorical.py @@ -930,8 +930,7 @@ def remove_unused_categories(self, inplace=False): return cat def map(self, mapper): - """ - Apply mapper function to its categories (not codes). + """Apply mapper function to its categories (not codes). Parameters ---------- @@ -944,6 +943,7 @@ def map(self, mapper): Returns ------- applied : Categorical or Index. + """ new_categories = self.categories.map(mapper) try: diff --git a/pandas/indexes/base.py b/pandas/indexes/base.py index 7fc6c1fb6e990..4589c1cef5206 100644 --- a/pandas/indexes/base.py +++ b/pandas/indexes/base.py @@ -2427,8 +2427,7 @@ def groupby(self, values): return result def map(self, mapper): - """ - Apply mapper function to an index. + """Apply mapper function to an index. Parameters ---------- @@ -2441,6 +2440,7 @@ def map(self, mapper): The output of the mapping function applied to the index. If the function returns a tuple with more than one element a MultiIndex will be returned. + """ from .multi import MultiIndex mapped_values = self._arrmap(self.values, mapper) diff --git a/pandas/indexes/category.py b/pandas/indexes/category.py index e87d44155d388..2c89f72975ade 100644 --- a/pandas/indexes/category.py +++ b/pandas/indexes/category.py @@ -517,8 +517,7 @@ def take(self, indices, axis=0, allow_fill=True, return self._create_from_codes(taken) def map(self, mapper): - """ - Apply mapper function to its categories (not codes). + """Apply mapper function to its categories (not codes). Parameters ---------- @@ -531,6 +530,7 @@ def map(self, mapper): Returns ------- applied : CategoricalIndex or Index + """ return self._shallow_copy_with_infer(self.values.map(mapper)) diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 56565c496cbf5..3536a52432b8c 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -770,7 +770,7 @@ def test_sub(self): def test_map_identity_mapping(self): # GH 12766 for name, cur_index in self.indices.items(): - self.assert_index_equal(cur_index, cur_index.map(lambda x: x)) + tm.assert_index_equal(cur_index, cur_index.map(lambda x: x)) def test_map_with_tuples(self): # GH 12766 @@ -779,35 +779,35 @@ def test_map_with_tuples(self): # returns an Index. boolean_index = tm.makeIntIndex(3).map(lambda x: (x,)) expected = Index([(0,), (1,), (2,)]) - self.assert_index_equal(boolean_index, expected) + tm.assert_index_equal(boolean_index, expected) # Test that returning a tuple from a map of a single index # returns a MultiIndex object. boolean_index = tm.makeIntIndex(3).map(lambda x: (x, x == 1)) expected = MultiIndex.from_tuples([(0, False), (1, True), (2, False)]) - self.assert_index_equal(boolean_index, expected) + tm.assert_index_equal(boolean_index, expected) # Test that returning a single object from a MultiIndex # returns an Index. first_level = ['foo', 'bar', 'baz'] multi_index = MultiIndex.from_tuples(lzip(first_level, [1, 2, 3])) reduced_index = multi_index.map(lambda x: x[0]) - self.assert_index_equal(reduced_index, Index(first_level)) + tm.assert_index_equal(reduced_index, Index(first_level)) def test_map_tseries_indices_return_index(self): date_index = tm.makeDateIndex(10) exp = Index([1] * 10) - self.assert_index_equal(exp, date_index.map(lambda x: 1)) + tm.assert_index_equal(exp, date_index.map(lambda x: 1)) period_index = tm.makePeriodIndex(10) - self.assert_index_equal(exp, period_index.map(lambda x: 1)) + tm.assert_index_equal(exp, period_index.map(lambda x: 1)) tdelta_index = tm.makeTimedeltaIndex(10) - self.assert_index_equal(exp, tdelta_index.map(lambda x: 1)) + tm.assert_index_equal(exp, tdelta_index.map(lambda x: 1)) date_index = tm.makeDateIndex(24, freq='h', name='hourly') exp = Index(range(24), name='hourly') - self.assert_index_equal(exp, date_index.map(lambda x: x.hour)) + tm.assert_index_equal(exp, date_index.map(lambda x: x.hour)) def test_append_multiple(self): index = Index(['a', 'b', 'c', 'd', 'e', 'f']) diff --git a/pandas/tseries/base.py b/pandas/tseries/base.py index aafa0dfb1e68a..b48f26e226540 100644 --- a/pandas/tseries/base.py +++ b/pandas/tseries/base.py @@ -27,7 +27,6 @@ from pandas.util.decorators import Appender, cache_readonly import pandas.types.concat as _concat import pandas.tseries.frequencies as frequencies -import pandas.algos as _algos class DatelikeOps(object): diff --git a/pandas/tseries/tests/test_timedeltas.py b/pandas/tseries/tests/test_timedeltas.py index d1e5379071b26..ca957ca0394d1 100644 --- a/pandas/tseries/tests/test_timedeltas.py +++ b/pandas/tseries/tests/test_timedeltas.py @@ -1514,7 +1514,7 @@ def test_map(self): f = lambda x: x.days result = rng.map(f) exp = Int64Index([f(x) for x in rng]) - self.assert_index_equal(result, exp) + tm.assert_index_equal(result, exp) def test_misc_coverage(self): diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py index 9aec391b33d9d..cd22ac561c6f7 100644 --- a/pandas/tseries/tests/test_timeseries.py +++ b/pandas/tseries/tests/test_timeseries.py @@ -3701,7 +3701,7 @@ def test_map_bug_1677(self): result = index.map(f) expected = Index([f(index[0])]) - self.assert_index_equal(result, expected) + tm.assert_index_equal(result, expected) def test_groupby_function_tuple_1677(self): df = DataFrame(np.random.rand(100),