Skip to content

Commit 3092629

Browse files
committed
SparseDataFrame: inherit default_kind and default_fill_value
1 parent f4dc43f commit 3092629

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

pandas/core/sparse/frame.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ def _apply_columns(self, func):
329329

330330
return self._constructor(
331331
data=new_data, index=self.index, columns=self.columns,
332-
default_fill_value=self.default_fill_value).__finalize__(self)
332+
default_fill_value=self.default_fill_value,
333+
default_kind=self.default_kind).__finalize__(self)
333334

334335
def astype(self, dtype):
335336
return self._apply_columns(lambda x: x.astype(dtype))
@@ -575,7 +576,8 @@ def _combine_frame(self, other, func, fill_value=None, level=None):
575576

576577
return self._constructor(data=new_data, index=new_index,
577578
columns=new_columns,
578-
default_fill_value=new_fill_value
579+
default_fill_value=new_fill_value,
580+
default_kind=self.default_kind,
579581
).__finalize__(self)
580582

581583
def _combine_match_index(self, other, func, level=None):
@@ -596,7 +598,6 @@ def _combine_match_index(self, other, func, level=None):
596598
new_data[col] = func(series.values, other.values)
597599

598600
# fill_value is a function of our operator
599-
fill_value = None
600601
if isna(other.fill_value) or isna(self.default_fill_value):
601602
fill_value = np.nan
602603
else:
@@ -605,7 +606,8 @@ def _combine_match_index(self, other, func, level=None):
605606

606607
return self._constructor(
607608
new_data, index=new_index, columns=self.columns,
608-
default_fill_value=fill_value).__finalize__(self)
609+
default_fill_value=fill_value,
610+
default_kind=self.default_kind).__finalize__(self)
609611

610612
def _combine_match_columns(self, other, func, level=None, try_cast=True):
611613
# patched version of DataFrame._combine_match_columns to account for
@@ -629,7 +631,8 @@ def _combine_match_columns(self, other, func, level=None, try_cast=True):
629631

630632
return self._constructor(
631633
new_data, index=self.index, columns=union,
632-
default_fill_value=self.default_fill_value).__finalize__(self)
634+
default_fill_value=self.default_fill_value,
635+
default_kind=self.default_kind).__finalize__(self)
633636

634637
def _combine_const(self, other, func, errors='raise', try_cast=True):
635638
return self._apply_columns(lambda x: func(x, other))
@@ -673,7 +676,8 @@ def _reindex_index(self, index, method, copy, level, fill_value=np.nan,
673676

674677
return self._constructor(
675678
new_series, index=index, columns=self.columns,
676-
default_fill_value=self._default_fill_value).__finalize__(self)
679+
default_fill_value=self._default_fill_value,
680+
default_kind=self.default_kind).__finalize__(self)
677681

678682
def _reindex_columns(self, columns, method, copy, level, fill_value=None,
679683
limit=None, takeable=False):
@@ -693,7 +697,8 @@ def _reindex_columns(self, columns, method, copy, level, fill_value=None,
693697
sdict = {k: v for k, v in compat.iteritems(self) if k in columns}
694698
return self._constructor(
695699
sdict, index=self.index, columns=columns,
696-
default_fill_value=self._default_fill_value).__finalize__(self)
700+
default_fill_value=self._default_fill_value,
701+
default_kind=self.default_kind).__finalize__(self)
697702

698703
def _reindex_with_indexers(self, reindexers, method=None, fill_value=None,
699704
limit=None, copy=False, allow_dups=False):
@@ -725,8 +730,10 @@ def _reindex_with_indexers(self, reindexers, method=None, fill_value=None,
725730
else:
726731
new_arrays[col] = self[col]
727732

728-
return self._constructor(new_arrays, index=index,
729-
columns=columns).__finalize__(self)
733+
return self._constructor(
734+
new_arrays, index=index, columns=columns,
735+
default_fill_value=self.default_fill_value,
736+
default_kind=self.default_kind).__finalize__(self)
730737

731738
def _join_compat(self, other, on=None, how='left', lsuffix='', rsuffix='',
732739
sort=False):

0 commit comments

Comments
 (0)