Skip to content

Commit a387110

Browse files
simonjayhawkinstopper-123
authored andcommitted
CLN: remove Panel-specific parts of core.generic (#26738)
1 parent c7748ca commit a387110

File tree

1 file changed

+6
-74
lines changed

1 file changed

+6
-74
lines changed

pandas/core/generic.py

+6-74
Original file line numberDiff line numberDiff line change
@@ -1570,11 +1570,6 @@ def _is_level_reference(self, key, axis=0):
15701570
"""
15711571
axis = self._get_axis_number(axis)
15721572

1573-
if self.ndim > 2:
1574-
raise NotImplementedError(
1575-
"_is_level_reference is not implemented for {type}"
1576-
.format(type=type(self)))
1577-
15781573
return (key is not None and
15791574
is_hashable(key) and
15801575
key in self.axes[axis].names and
@@ -1600,11 +1595,6 @@ def _is_label_reference(self, key, axis=0):
16001595
-------
16011596
is_label: bool
16021597
"""
1603-
if self.ndim > 2:
1604-
raise NotImplementedError(
1605-
"_is_label_reference is not implemented for {type}"
1606-
.format(type=type(self)))
1607-
16081598
axis = self._get_axis_number(axis)
16091599
other_axes = (ax for ax in range(self._AXIS_LEN) if ax != axis)
16101600

@@ -1632,12 +1622,6 @@ def _is_label_or_level_reference(self, key, axis=0):
16321622
-------
16331623
is_label_or_level: bool
16341624
"""
1635-
1636-
if self.ndim > 2:
1637-
raise NotImplementedError(
1638-
"_is_label_or_level_reference is not implemented for {type}"
1639-
.format(type=type(self)))
1640-
16411625
return (self._is_level_reference(key, axis=axis) or
16421626
self._is_label_reference(key, axis=axis))
16431627

@@ -1659,11 +1643,6 @@ def _check_label_or_level_ambiguity(self, key, axis=0):
16591643
------
16601644
ValueError: `key` is ambiguous
16611645
"""
1662-
if self.ndim > 2:
1663-
raise NotImplementedError(
1664-
"_check_label_or_level_ambiguity is not implemented for {type}"
1665-
.format(type=type(self)))
1666-
16671646
axis = self._get_axis_number(axis)
16681647
other_axes = (ax for ax in range(self._AXIS_LEN) if ax != axis)
16691648

@@ -1724,11 +1703,6 @@ def _get_label_or_level_values(self, key, axis=0):
17241703
if `key` is ambiguous. This will become an ambiguity error in a
17251704
future version
17261705
"""
1727-
if self.ndim > 2:
1728-
raise NotImplementedError(
1729-
"_get_label_or_level_values is not implemented for {type}"
1730-
.format(type=type(self)))
1731-
17321706
axis = self._get_axis_number(axis)
17331707
other_axes = [ax for ax in range(self._AXIS_LEN) if ax != axis]
17341708

@@ -1787,11 +1761,6 @@ def _drop_labels_or_levels(self, keys, axis=0):
17871761
ValueError
17881762
if any `keys` match neither a label nor a level
17891763
"""
1790-
if self.ndim > 2:
1791-
raise NotImplementedError(
1792-
"_drop_labels_or_levels is not implemented for {type}"
1793-
.format(type=type(self)))
1794-
17951764
axis = self._get_axis_number(axis)
17961765

17971766
# Validate keys
@@ -2781,7 +2750,6 @@ class (index) object 'bird' 'bird' 'mammal' 'mammal'
27812750
Data variables:
27822751
speed (date, animal) int64 350 18 361 15
27832752
"""
2784-
27852753
try:
27862754
import xarray
27872755
except ImportError:
@@ -2794,15 +2762,9 @@ class (index) object 'bird' 'bird' 'mammal' 'mammal'
27942762

27952763
if self.ndim == 1:
27962764
return xarray.DataArray.from_series(self)
2797-
elif self.ndim == 2:
2765+
else:
27982766
return xarray.Dataset.from_dataframe(self)
27992767

2800-
# > 2 dims
2801-
coords = [(a, self._get_axis(a)) for a in self._AXIS_ORDERS]
2802-
return xarray.DataArray(self,
2803-
coords=coords,
2804-
)
2805-
28062768
def to_latex(self, buf=None, columns=None, col_space=None, header=True,
28072769
index=True, na_rep='NaN', formatters=None, float_format=None,
28082770
sparsify=None, index_names=True, bold_rows=False,
@@ -5692,11 +5654,7 @@ def astype(self, dtype, copy=True, errors='raise', **kwargs):
56925654
'the key in Series dtype mappings.')
56935655
new_type = dtype[self.name]
56945656
return self.astype(new_type, copy, errors, **kwargs)
5695-
elif self.ndim > 2:
5696-
raise NotImplementedError(
5697-
'astype() only accepts a dtype arg of type dict when '
5698-
'invoked on Series and DataFrames.'
5699-
)
5657+
57005658
for col_name in dtype.keys():
57015659
if col_name not in self:
57025660
raise KeyError('Only a column name can be used for the '
@@ -6051,26 +6009,10 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,
60516009

60526010
return result
60536011

6054-
# > 3d
6055-
if self.ndim > 3:
6056-
raise NotImplementedError('Cannot fillna with a method for > '
6057-
'3dims')
6058-
6059-
# 3d
6060-
elif self.ndim == 3:
6061-
# fill in 2d chunks
6062-
result = {col: s.fillna(method=method, value=value)
6063-
for col, s in self.iteritems()}
6064-
prelim_obj = self._constructor.from_dict(result)
6065-
new_obj = prelim_obj.__finalize__(self)
6066-
new_data = new_obj._data
6067-
6068-
else:
6069-
# 2d or less
6070-
new_data = self._data.interpolate(method=method, axis=axis,
6071-
limit=limit, inplace=inplace,
6072-
coerce=True,
6073-
downcast=downcast)
6012+
new_data = self._data.interpolate(method=method, axis=axis,
6013+
limit=limit, inplace=inplace,
6014+
coerce=True,
6015+
downcast=downcast)
60746016
else:
60756017
if len(self._get_axis(axis)) == 0:
60766018
return self
@@ -6782,9 +6724,6 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
67826724
"""
67836725
inplace = validate_bool_kwarg(inplace, 'inplace')
67846726

6785-
if self.ndim > 2:
6786-
raise NotImplementedError("Interpolate has not been implemented ")
6787-
67886727
if axis == 0:
67896728
ax = self._info_axis_name
67906729
_maybe_transposed_self = self
@@ -6964,9 +6903,6 @@ def asof(self, where, subset=None):
69646903
if is_series:
69656904
if subset is not None:
69666905
raise ValueError("subset is not valid for Series")
6967-
elif self.ndim > 2:
6968-
raise NotImplementedError("asof is not implemented "
6969-
"for {type}".format(type=type(self)))
69706906
else:
69716907
if subset is None:
69726908
subset = self.columns
@@ -8373,10 +8309,6 @@ def rank(self, axis=0, method='average', numeric_only=None,
83738309
"""
83748310
axis = self._get_axis_number(axis)
83758311

8376-
if self.ndim > 2:
8377-
msg = "rank does not make sense when ndim > 2"
8378-
raise NotImplementedError(msg)
8379-
83808312
if na_option not in {'keep', 'top', 'bottom'}:
83818313
msg = "na_option must be one of 'keep', 'top', or 'bottom'"
83828314
raise ValueError(msg)

0 commit comments

Comments
 (0)