Skip to content

Commit 2f182aa

Browse files
WillAydjreback
authored andcommitted
Remove Panel References (#26287)
1 parent 64c1127 commit 2f182aa

File tree

10 files changed

+22
-211
lines changed

10 files changed

+22
-211
lines changed

pandas/compat/numpy/function.py

-17
Original file line numberDiff line numberDiff line change
@@ -287,23 +287,6 @@ def validate_take_with_convert(convert, args, kwargs):
287287
method='both', max_fname_arg_count=0)
288288

289289

290-
def validate_transpose_for_generic(inst, kwargs):
291-
try:
292-
validate_transpose(tuple(), kwargs)
293-
except ValueError as e:
294-
klass = type(inst).__name__
295-
msg = str(e)
296-
297-
# the Panel class actual relies on the 'axes' parameter if called
298-
# via the 'numpy' library, so let's make sure the error is specific
299-
# about saying that the parameter is not supported for particular
300-
# implementations of 'transpose'
301-
if "the 'axes' parameter is not supported" in msg:
302-
msg += " for {klass} instances".format(klass=klass)
303-
304-
raise ValueError(msg)
305-
306-
307290
def validate_window_func(name, args, kwargs):
308291
numpy_args = ('axis', 'dtype', 'out')
309292
msg = ("numpy operations are not "

pandas/core/frame.py

+2-21
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,7 @@ def _constructor(self):
368368

369369
@property
370370
def _constructor_expanddim(self):
371-
# TODO: Raise NotImplementedError or change note in extending.rst
372-
from pandas.core.panel import Panel
373-
return Panel
371+
raise NotImplementedError("Not supported for DataFrames!")
374372

375373
# ----------------------------------------------------------------------
376374
# Constructors
@@ -1934,22 +1932,6 @@ def to_sparse(self, fill_value=None, kind='block'):
19341932
columns=self.columns, default_kind=kind,
19351933
default_fill_value=fill_value)
19361934

1937-
def to_panel(self):
1938-
"""
1939-
Transform long (stacked) format (DataFrame) into wide (3D, Panel)
1940-
format.
1941-
1942-
.. deprecated:: 0.20.0
1943-
1944-
Currently the index of the DataFrame must be a 2-level MultiIndex. This
1945-
may be generalized later
1946-
1947-
Returns
1948-
-------
1949-
Panel
1950-
"""
1951-
raise NotImplementedError("Panel is being removed in pandas 0.25.0.")
1952-
19531935
@deprecate_kwarg(old_arg_name='encoding', new_arg_name=None)
19541936
def to_stata(self, fname, convert_dates=None, write_index=True,
19551937
encoding="latin-1", byteorder=None, time_stamp=None,
@@ -6638,8 +6620,7 @@ def append(self, other, ignore_index=False,
66386620
66396621
See Also
66406622
--------
6641-
concat : General function to concatenate DataFrame, Series
6642-
or Panel objects.
6623+
concat : General function to concatenate DataFrame or Series objects.
66436624
66446625
Notes
66456626
-----

pandas/core/generic.py

+15-25
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
is_dict_like, is_extension_array_dtype, is_integer, is_list_like,
3030
is_number, is_numeric_dtype, is_object_dtype, is_period_arraylike,
3131
is_re_compilable, is_scalar, is_timedelta64_dtype, pandas_dtype)
32-
from pandas.core.dtypes.generic import ABCDataFrame, ABCPanel, ABCSeries
32+
from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
3333
from pandas.core.dtypes.inference import is_hashable
3434
from pandas.core.dtypes.missing import isna, notna
3535

@@ -688,7 +688,7 @@ def transpose(self, *args, **kwargs):
688688
if kwargs.pop('copy', None) or (len(args) and args[-1]):
689689
new_values = new_values.copy()
690690

691-
nv.validate_transpose_for_generic(self, kwargs)
691+
nv.validate_transpose(tuple(), kwargs)
692692
return self._constructor(new_values, **new_axes).__finalize__(self)
693693

694694
def swapaxes(self, axis1, axis2, copy=True):
@@ -978,7 +978,7 @@ def rename(self, *args, **kwargs):
978978
----------
979979
%(axes)s : scalar, list-like, dict-like or function, optional
980980
Scalar or list-like will alter the ``Series.name`` attribute,
981-
and raise on DataFrame or Panel.
981+
and raise on DataFrame.
982982
dict-like or functions are transformations to apply to
983983
that axis' values
984984
copy : bool, default True
@@ -1852,16 +1852,14 @@ def __iter__(self):
18521852
def keys(self):
18531853
"""Get the 'info axis' (see Indexing for more)
18541854
1855-
This is index for Series, columns for DataFrame and major_axis for
1856-
Panel.
1855+
This is index for Series, columns for DataFrame.
18571856
"""
18581857
return self._info_axis
18591858

18601859
def iteritems(self):
18611860
"""Iterate over (label, values) on info axis
18621861
1863-
This is index for Series, columns for DataFrame, major_axis for Panel,
1864-
and so on.
1862+
This is index for Series, columns for DataFrame and so on.
18651863
"""
18661864
for h in self._info_axis:
18671865
yield h, self[h]
@@ -3063,8 +3061,9 @@ def _create_indexer(cls, name, indexer):
30633061

30643062
def get(self, key, default=None):
30653063
"""
3066-
Get item from object for given key (DataFrame column, Panel slice,
3067-
etc.). Returns default value if not found.
3064+
Get item from object for given key (ex: DataFrame column).
3065+
3066+
Returns default value if not found.
30683067
30693068
Parameters
30703069
----------
@@ -4091,8 +4090,7 @@ def sort_values(self, by=None, axis=0, ascending=True, inplace=False,
40914090
0 A 2 0
40924091
1 A 1 1
40934092
"""
4094-
raise NotImplementedError("sort_values has not been implemented "
4095-
"on Panel or Panel4D objects.")
4093+
raise AbstractMethodError(self)
40964094

40974095
def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
40984096
kind='quicksort', na_position='last', sort_remaining=True):
@@ -4770,7 +4768,7 @@ def sample(self, n=None, frac=None, replace=False, weights=None,
47704768
object.
47714769
axis : int or string, optional
47724770
Axis to sample. Accepts axis number or name. Default is stat axis
4773-
for given data type (0 for Series and DataFrames, 1 for Panels).
4771+
for given data type (0 for Series and DataFrames).
47744772
47754773
Returns
47764774
-------
@@ -4853,7 +4851,7 @@ def sample(self, n=None, frac=None, replace=False, weights=None,
48534851
"a DataFrame")
48544852
else:
48554853
raise ValueError("Strings cannot be passed as weights "
4856-
"when sampling from a Series or Panel.")
4854+
"when sampling from a Series.")
48574855

48584856
weights = pd.Series(weights, dtype='float64')
48594857

@@ -5697,8 +5695,7 @@ def astype(self, dtype, copy=True, errors='raise', **kwargs):
56975695
elif self.ndim > 2:
56985696
raise NotImplementedError(
56995697
'astype() only accepts a dtype arg of type dict when '
5700-
'invoked on Series and DataFrames. A single dtype must be '
5701-
'specified when invoked on a Panel.'
5698+
'invoked on Series and DataFrames.'
57025699
)
57035700
for col_name in dtype.keys():
57045701
if col_name not in self:
@@ -5751,7 +5748,7 @@ def copy(self, deep=True):
57515748
57525749
Returns
57535750
-------
5754-
copy : Series, DataFrame or Panel
5751+
copy : Series or DataFrame
57555752
Object type matches caller.
57565753
57575754
Notes
@@ -6822,8 +6819,7 @@ def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
68226819
inplace = validate_bool_kwarg(inplace, 'inplace')
68236820

68246821
if self.ndim > 2:
6825-
raise NotImplementedError("Interpolate has not been implemented "
6826-
"on Panel and Panel 4D objects.")
6822+
raise NotImplementedError("Interpolate has not been implemented ")
68276823

68286824
if axis == 0:
68296825
ax = self._info_axis_name
@@ -7326,9 +7322,6 @@ def clip(self, lower=None, upper=None, axis=None, inplace=False,
73267322
3 6 8
73277323
4 5 3
73287324
"""
7329-
if isinstance(self, ABCPanel):
7330-
raise NotImplementedError("clip is not supported yet for panels")
7331-
73327325
inplace = validate_bool_kwarg(inplace, 'inplace')
73337326

73347327
axis = nv.validate_clip_with_axis(axis, args, kwargs)
@@ -9824,10 +9817,7 @@ def describe(self, percentiles=None, include=None, exclude=None):
98249817
75% NaN 2.5
98259818
max NaN 3.0
98269819
"""
9827-
if self.ndim >= 3:
9828-
msg = "describe is not implemented on Panel objects."
9829-
raise NotImplementedError(msg)
9830-
elif self.ndim == 2 and self.columns.size == 0:
9820+
if self.ndim == 2 and self.columns.size == 0:
98319821
raise ValueError("Cannot describe a DataFrame without columns")
98329822

98339823
if percentiles is not None:

pandas/core/groupby/groupby.py

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class providing the base-class of operations.
5151
--------
5252
Series.%(name)s
5353
DataFrame.%(name)s
54-
Panel.%(name)s
5554
"""
5655

5756
_apply_docs = dict(

pandas/core/ops.py

+2-138
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
is_integer_dtype, is_list_like, is_object_dtype, is_period_dtype,
2424
is_scalar, is_timedelta64_dtype, needs_i8_conversion)
2525
from pandas.core.dtypes.generic import (
26-
ABCDataFrame, ABCIndex, ABCIndexClass, ABCPanel, ABCSeries, ABCSparseArray,
26+
ABCDataFrame, ABCIndex, ABCIndexClass, ABCSeries, ABCSparseArray,
2727
ABCSparseSeries)
2828
from pandas.core.dtypes.missing import isna, notna
2929

@@ -234,7 +234,7 @@ def _gen_eval_kwargs(name):
234234
"""
235235
kwargs = {}
236236

237-
# Series and Panel appear to only pass __add__, __radd__, ...
237+
# Series appear to only pass __add__, __radd__, ...
238238
# but DataFrame gets both these dunder names _and_ non-dunder names
239239
# add, radd, ...
240240
name = name.replace('__', '')
@@ -991,40 +991,6 @@ def _get_op_name(op, special):
991991
C True False
992992
"""
993993

994-
_flex_doc_PANEL = """
995-
Return {desc} of series and other, element-wise (binary operator `{op_name}`).
996-
Equivalent to ``{equiv}``.
997-
998-
Parameters
999-
----------
1000-
other : DataFrame or Panel
1001-
axis : {{items, major_axis, minor_axis}}
1002-
Axis to broadcast over
1003-
1004-
Returns
1005-
-------
1006-
Panel
1007-
1008-
See Also
1009-
--------
1010-
Panel.{reverse}
1011-
"""
1012-
1013-
1014-
_agg_doc_PANEL = """
1015-
Wrapper method for {op_name}
1016-
1017-
Parameters
1018-
----------
1019-
other : DataFrame or Panel
1020-
axis : {{items, major_axis, minor_axis}}
1021-
Axis to broadcast over
1022-
1023-
Returns
1024-
-------
1025-
Panel
1026-
"""
1027-
1028994

1029995
def _make_flex_doc(op_name, typ):
1030996
"""
@@ -1069,14 +1035,6 @@ def _make_flex_doc(op_name, typ):
10691035
equiv=equiv,
10701036
reverse=op_desc['reverse']
10711037
)
1072-
elif typ == 'panel':
1073-
base_doc = _flex_doc_PANEL
1074-
doc = base_doc.format(
1075-
desc=op_desc['desc'],
1076-
op_name=op_name,
1077-
equiv=equiv,
1078-
reverse=op_desc['reverse']
1079-
)
10801038
else:
10811039
raise AssertionError('Invalid typ argument.')
10821040
return doc
@@ -1457,12 +1415,6 @@ def _get_method_wrappers(cls):
14571415
arith_special = _arith_method_SPARSE_ARRAY
14581416
comp_special = _arith_method_SPARSE_ARRAY
14591417
bool_special = _arith_method_SPARSE_ARRAY
1460-
elif issubclass(cls, ABCPanel):
1461-
arith_flex = _flex_method_PANEL
1462-
comp_flex = _comp_method_PANEL
1463-
arith_special = _arith_method_PANEL
1464-
comp_special = _comp_method_PANEL
1465-
bool_special = _arith_method_PANEL
14661418
elif issubclass(cls, ABCDataFrame):
14671419
# Same for DataFrame and SparseDataFrame
14681420
arith_flex = _arith_method_FRAME
@@ -2295,94 +2247,6 @@ def f(self, other):
22952247
return f
22962248

22972249

2298-
# -----------------------------------------------------------------------------
2299-
# Panel
2300-
2301-
def _arith_method_PANEL(cls, op, special):
2302-
# work only for scalars
2303-
op_name = _get_op_name(op, special)
2304-
2305-
def f(self, other):
2306-
if not is_scalar(other):
2307-
raise ValueError('Simple arithmetic with {name} can only be '
2308-
'done with scalar values'
2309-
.format(name=self._constructor.__name__))
2310-
2311-
return self._combine(other, op)
2312-
2313-
f.__name__ = op_name
2314-
return f
2315-
2316-
2317-
def _comp_method_PANEL(cls, op, special):
2318-
str_rep = _get_opstr(op, cls)
2319-
op_name = _get_op_name(op, special)
2320-
2321-
def na_op(x, y):
2322-
import pandas.core.computation.expressions as expressions
2323-
2324-
try:
2325-
result = expressions.evaluate(op, str_rep, x, y)
2326-
except TypeError:
2327-
result = mask_cmp_op(x, y, op, np.ndarray)
2328-
return result
2329-
2330-
@Appender('Wrapper for comparison method {name}'.format(name=op_name))
2331-
def f(self, other, axis=None):
2332-
# Validate the axis parameter
2333-
if axis is not None:
2334-
self._get_axis_number(axis)
2335-
2336-
if isinstance(other, self._constructor):
2337-
return self._compare_constructor(other, na_op)
2338-
elif isinstance(other, (self._constructor_sliced, ABCDataFrame,
2339-
ABCSeries)):
2340-
raise Exception("input needs alignment for this object [{object}]"
2341-
.format(object=self._constructor))
2342-
else:
2343-
return self._combine_const(other, na_op)
2344-
2345-
f.__name__ = op_name
2346-
2347-
return f
2348-
2349-
2350-
def _flex_method_PANEL(cls, op, special):
2351-
str_rep = _get_opstr(op, cls)
2352-
op_name = _get_op_name(op, special)
2353-
eval_kwargs = _gen_eval_kwargs(op_name)
2354-
fill_zeros = _gen_fill_zeros(op_name)
2355-
2356-
def na_op(x, y):
2357-
import pandas.core.computation.expressions as expressions
2358-
2359-
try:
2360-
result = expressions.evaluate(op, str_rep, x, y,
2361-
errors='raise',
2362-
**eval_kwargs)
2363-
except TypeError:
2364-
result = op(x, y)
2365-
2366-
# handles discrepancy between numpy and numexpr on division/mod
2367-
# by 0 though, given that these are generally (always?)
2368-
# non-scalars, I'm not sure whether it's worth it at the moment
2369-
result = missing.fill_zeros(result, x, y, op_name, fill_zeros)
2370-
return result
2371-
2372-
if op_name in _op_descriptions:
2373-
doc = _make_flex_doc(op_name, 'panel')
2374-
else:
2375-
# doc strings substitors
2376-
doc = _agg_doc_PANEL.format(op_name=op_name)
2377-
2378-
@Appender(doc)
2379-
def f(self, other, axis=0):
2380-
return self._combine(other, na_op, axis=axis)
2381-
2382-
f.__name__ = op_name
2383-
return f
2384-
2385-
23862250
# -----------------------------------------------------------------------------
23872251
# Sparse
23882252

0 commit comments

Comments
 (0)