Skip to content

Commit

Permalink
Fix unused import and docstrings per pep8radius docformatter; change …
Browse files Browse the repository at this point in the history
…other uses of assert_index_equal to testing instead os self
  • Loading branch information
nateyoder committed Dec 16, 2016
1 parent ab168e7 commit a17ddab
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions pandas/core/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -944,6 +943,7 @@ def map(self, mapper):
Returns
-------
applied : Categorical or Index.
"""
new_categories = self.categories.map(mapper)
try:
Expand Down
4 changes: 2 additions & 2 deletions pandas/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pandas/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------
Expand All @@ -531,6 +530,7 @@ def map(self, mapper):
Returns
-------
applied : CategoricalIndex or Index
"""
return self._shallow_copy_with_infer(self.values.map(mapper))

Expand Down
16 changes: 8 additions & 8 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'])
Expand Down
1 change: 0 additions & 1 deletion pandas/tseries/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/tests/test_timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit a17ddab

Please sign in to comment.