Skip to content

BUG: SparseSeries.abs() resets name #10241

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
Jun 2, 2015
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Bug Fixes
- Bug in `plot` not defaulting to matplotlib `axes.grid` setting (:issue:`9792`)

- Bug in ``Series.align`` resets ``name`` when ``fill_value`` is specified (:issue:`10067`)

- Bug in ``SparseSeries.abs`` resets ``name`` (:issue:`10241`)


- Bug in GroupBy.get_group raises ValueError when group key contains NaT (:issue:`6992`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/sparse/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def abs(self):
res_sp_values = np.abs(self.sp_values)
return self._constructor(res_sp_values, index=self.index,
sparse_index=self.sp_index,
fill_value=self.fill_value)
fill_value=self.fill_value).__finalize__(self)

def get(self, label, default=None):
"""
Expand Down
15 changes: 15 additions & 0 deletions pandas/sparse/tests/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,21 @@ def _check_inplace_op(iop, op):
_check_inplace_op(
getattr(operator, "i%s" % op), getattr(operator, op))

def test_abs(self):
s = SparseSeries([1, 2, -3], name='x')
expected = SparseSeries([1, 2, 3], name='x')
result = s.abs()
assert_sp_series_equal(result, expected)
self.assertEqual(result.name, 'x')

result = abs(s)
assert_sp_series_equal(result, expected)
self.assertEqual(result.name, 'x')

result = np.abs(s)
assert_sp_series_equal(result, expected)
self.assertEqual(result.name, 'x')

def test_reindex(self):
def _compare_with_series(sps, new_index):
spsre = sps.reindex(new_index)
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@ def test_abs(self):
expected = np.abs(s)
assert_series_equal(result, expected)
assert_series_equal(result2, expected)
self.assertEqual(result.name, 'A')
self.assertEqual(result2.name, 'A')


class CheckIndexing(object):
Expand Down