-
-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
Bugfix: Couldn't subclass Panel #888
Changes from 3 commits
5c8347b
76781c8
4390aa3
19d7703
cfecd66
dc78377
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,7 +320,7 @@ def from_dict(cls, data, intersect=False, orient='items', dtype=None): | |
data, index, columns = _homogenize_dict(data, intersect=intersect, | ||
dtype=dtype) | ||
items = Index(sorted(data.keys())) | ||
return Panel(data, items, index, columns) | ||
return __class__(data, items, index, columns) | ||
|
||
def __getitem__(self, key): | ||
if isinstance(self.items, MultiIndex): | ||
|
@@ -441,7 +441,7 @@ def _get_plane_axes(self, axis): | |
|
||
@property | ||
def _constructor(self): | ||
return Panel | ||
return self.__class__ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general I'd prefer |
||
|
||
# Fancy indexing | ||
_ix = None | ||
|
@@ -723,7 +723,7 @@ def _combine(self, other, func, axis=0): | |
return self._combine_frame(other, func, axis=axis) | ||
elif np.isscalar(other): | ||
new_values = func(self.values, other) | ||
return Panel(new_values, self.items, self.major_axis, | ||
return self._constructor(new_values, self.items, self.major_axis, | ||
self.minor_axis) | ||
|
||
def __neg__(self): | ||
|
@@ -744,7 +744,7 @@ def _combine_frame(self, other, func, axis=0): | |
new_values = func(self.values.swapaxes(0, 2), other.values) | ||
new_values = new_values.swapaxes(0, 2) | ||
|
||
return Panel(new_values, self.items, self.major_axis, | ||
return self._constructor(new_values, self.items, self.major_axis, | ||
self.minor_axis) | ||
|
||
def _combine_panel(self, other, func): | ||
|
@@ -758,7 +758,7 @@ def _combine_panel(self, other, func): | |
|
||
result_values = func(this.values, other.values) | ||
|
||
return Panel(result_values, items, major, minor) | ||
return self._constructor(result_values, items, major, minor) | ||
|
||
def fillna(self, value=None, method='pad'): | ||
""" | ||
|
@@ -790,10 +790,10 @@ def fillna(self, value=None, method='pad'): | |
for col, s in self.iterkv(): | ||
result[col] = s.fillna(method=method, value=value) | ||
|
||
return Panel.from_dict(result) | ||
return self._constructor.from_dict(result) | ||
else: | ||
new_data = self._data.fillna(value) | ||
return Panel(new_data) | ||
return self._constructor(new_data) | ||
|
||
add = _panel_arith_method(operator.add, 'add') | ||
subtract = sub = _panel_arith_method(operator.sub, 'subtract') | ||
|
@@ -882,7 +882,7 @@ def groupby(self, function, axis='major'): | |
""" | ||
from pandas.core.groupby import PanelGroupBy | ||
axis = self._get_axis_number(axis) | ||
return PanelGroupBy(self, function, axis=axis) | ||
return self._constructorGroupBy(self, function, axis=axis) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see a |
||
|
||
def swapaxes(self, axis1='major', axis2='minor'): | ||
""" | ||
|
@@ -904,7 +904,7 @@ def swapaxes(self, axis1='major', axis2='minor'): | |
for k in range(3)) | ||
new_values = self.values.swapaxes(i, j).copy() | ||
|
||
return Panel(new_values, *new_axes) | ||
return self._constructor(new_values, *new_axes) | ||
|
||
def to_frame(self, filter_observations=True): | ||
""" | ||
|
@@ -1105,7 +1105,7 @@ def shift(self, lags, axis='major'): | |
else: | ||
raise ValueError('Invalid axis') | ||
|
||
return Panel(values, items=items, major_axis=major_axis, | ||
return self._constructor(values, items=items, major_axis=major_axis, | ||
minor_axis=minor_axis) | ||
|
||
def truncate(self, before=None, after=None, axis='major'): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be
cls
rather than__class__
?