Skip to content

Bugfix: Couldn't subclass Panel #888

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 6 commits into from
Closed
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
18 changes: 9 additions & 9 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 cls(data, items, index, columns)

def __getitem__(self, key):
if isinstance(self.items, MultiIndex):
Expand Down Expand Up @@ -441,7 +441,7 @@ def _get_plane_axes(self, axis):

@property
def _constructor(self):
return Panel
return type(self)

# Fancy indexing
_ix = None
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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'):
"""
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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'):
Expand Down