Skip to content

BUG: Slicing subclasses of SparseDataFrames. #13787

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

Closed
wants to merge 12 commits into from
Closed
Prev Previous commit
Next Next commit
Further SparseSeries subclass fixes.
  • Loading branch information
sstanovnik committed Aug 1, 2016
commit 0387303c6054233c7f1884a876aefb2e0979c8ee
12 changes: 6 additions & 6 deletions pandas/sparse/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ def wrapper(self, other):
new_fill_value = op(np.float64(self.fill_value),
np.float64(other))

return SparseSeries(op(self.sp_values, other),
index=self.index,
sparse_index=self.sp_index,
fill_value=new_fill_value,
name=self.name)
return self._constructor(op(self.sp_values, other),
index=self.index,
sparse_index=self.sp_index,
fill_value=new_fill_value,
name=self.name)
else: # pragma: no cover
raise TypeError('operation with %s not supported' % type(other))

Expand All @@ -85,7 +85,7 @@ def _sparse_series_op(left, right, op, name):
new_name = _maybe_match_name(left, right)

result = _sparse_array_op(left, right, op, name)
return SparseSeries(result, index=new_index, name=new_name)
return left._constructor(result, index=new_index, name=new_name)


class SparseSeries(Series):
Expand Down
5 changes: 4 additions & 1 deletion pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,10 @@ def assert_sp_series_equal(left, right, exact_indices=True,
assertIsInstance(left, pd.SparseSeries, '[SparseSeries]')
assertIsInstance(right, pd.SparseSeries, '[SparseSeries]')

if check_series_type:
# SparseTimeSeries is deprecated, some pickling checks fail on this condition
from pandas import SparseTimeSeries
if check_series_type and not (isinstance(left, SparseTimeSeries)
or isinstance(right, SparseTimeSeries)):
assert_class_equal(left, right, obj=obj)

assert_index_equal(left.index, right.index,
Expand Down