Skip to content

CLN: remove Panel-specific parts of core.generic #26738

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 4 commits into from
Jun 9, 2019
Merged
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
80 changes: 6 additions & 74 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,11 +1570,6 @@ def _is_level_reference(self, key, axis=0):
"""
axis = self._get_axis_number(axis)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I wouldn't worry about checking ndim at all in any methods and just remove all of the checks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good. thanks.


if self.ndim > 2:
raise NotImplementedError(
"_is_level_reference is not implemented for {type}"
.format(type=type(self)))

return (key is not None and
is_hashable(key) and
key in self.axes[axis].names and
Expand All @@ -1600,11 +1595,6 @@ def _is_label_reference(self, key, axis=0):
-------
is_label: bool
"""
if self.ndim > 2:
raise NotImplementedError(
"_is_label_reference is not implemented for {type}"
.format(type=type(self)))

axis = self._get_axis_number(axis)
other_axes = (ax for ax in range(self._AXIS_LEN) if ax != axis)

Expand Down Expand Up @@ -1632,12 +1622,6 @@ def _is_label_or_level_reference(self, key, axis=0):
-------
is_label_or_level: bool
"""

if self.ndim > 2:
raise NotImplementedError(
"_is_label_or_level_reference is not implemented for {type}"
.format(type=type(self)))

return (self._is_level_reference(key, axis=axis) or
self._is_label_reference(key, axis=axis))

Expand All @@ -1659,11 +1643,6 @@ def _check_label_or_level_ambiguity(self, key, axis=0):
------
ValueError: `key` is ambiguous
"""
if self.ndim > 2:
raise NotImplementedError(
"_check_label_or_level_ambiguity is not implemented for {type}"
.format(type=type(self)))

axis = self._get_axis_number(axis)
other_axes = (ax for ax in range(self._AXIS_LEN) if ax != axis)

Expand Down Expand Up @@ -1724,11 +1703,6 @@ def _get_label_or_level_values(self, key, axis=0):
if `key` is ambiguous. This will become an ambiguity error in a
future version
"""
if self.ndim > 2:
raise NotImplementedError(
"_get_label_or_level_values is not implemented for {type}"
.format(type=type(self)))

axis = self._get_axis_number(axis)
other_axes = [ax for ax in range(self._AXIS_LEN) if ax != axis]

Expand Down Expand Up @@ -1787,11 +1761,6 @@ def _drop_labels_or_levels(self, keys, axis=0):
ValueError
if any `keys` match neither a label nor a level
"""
if self.ndim > 2:
raise NotImplementedError(
"_drop_labels_or_levels is not implemented for {type}"
.format(type=type(self)))

axis = self._get_axis_number(axis)

# Validate keys
Expand Down Expand Up @@ -2781,7 +2750,6 @@ class (index) object 'bird' 'bird' 'mammal' 'mammal'
Data variables:
speed (date, animal) int64 350 18 361 15
"""

try:
import xarray
except ImportError:
Expand All @@ -2794,15 +2762,9 @@ class (index) object 'bird' 'bird' 'mammal' 'mammal'

if self.ndim == 1:
return xarray.DataArray.from_series(self)
elif self.ndim == 2:
else:
return xarray.Dataset.from_dataframe(self)

# > 2 dims
coords = [(a, self._get_axis(a)) for a in self._AXIS_ORDERS]
return xarray.DataArray(self,
coords=coords,
)

def to_latex(self, buf=None, columns=None, col_space=None, header=True,
index=True, na_rep='NaN', formatters=None, float_format=None,
sparsify=None, index_names=True, bold_rows=False,
Expand Down Expand Up @@ -5692,11 +5654,7 @@ def astype(self, dtype, copy=True, errors='raise', **kwargs):
'the key in Series dtype mappings.')
new_type = dtype[self.name]
return self.astype(new_type, copy, errors, **kwargs)
elif self.ndim > 2:
raise NotImplementedError(
'astype() only accepts a dtype arg of type dict when '
'invoked on Series and DataFrames.'
)

for col_name in dtype.keys():
if col_name not in self:
raise KeyError('Only a column name can be used for the '
Expand Down Expand Up @@ -6051,26 +6009,10 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,

return result

# > 3d
if self.ndim > 3:
raise NotImplementedError('Cannot fillna with a method for > '
'3dims')

# 3d
elif self.ndim == 3:
# fill in 2d chunks
result = {col: s.fillna(method=method, value=value)
for col, s in self.iteritems()}
prelim_obj = self._constructor.from_dict(result)
new_obj = prelim_obj.__finalize__(self)
new_data = new_obj._data

else:
# 2d or less
new_data = self._data.interpolate(method=method, axis=axis,
limit=limit, inplace=inplace,
coerce=True,
downcast=downcast)
new_data = self._data.interpolate(method=method, axis=axis,
limit=limit, inplace=inplace,
coerce=True,
downcast=downcast)
else:
if len(self._get_axis(axis)) == 0:
return self
Expand Down Expand Up @@ -6782,9 +6724,6 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
"""
inplace = validate_bool_kwarg(inplace, 'inplace')

if self.ndim > 2:
raise NotImplementedError("Interpolate has not been implemented ")

if axis == 0:
ax = self._info_axis_name
_maybe_transposed_self = self
Expand Down Expand Up @@ -6964,9 +6903,6 @@ def asof(self, where, subset=None):
if is_series:
if subset is not None:
raise ValueError("subset is not valid for Series")
elif self.ndim > 2:
raise NotImplementedError("asof is not implemented "
"for {type}".format(type=type(self)))
else:
if subset is None:
subset = self.columns
Expand Down Expand Up @@ -8373,10 +8309,6 @@ def rank(self, axis=0, method='average', numeric_only=None,
"""
axis = self._get_axis_number(axis)

if self.ndim > 2:
msg = "rank does not make sense when ndim > 2"
raise NotImplementedError(msg)

if na_option not in {'keep', 'top', 'bottom'}:
msg = "na_option must be one of 'keep', 'top', or 'bottom'"
raise ValueError(msg)
Expand Down