Skip to content

Remove Panel References #26287

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 6 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 1 addition & 14 deletions pandas/compat/numpy/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,20 +288,7 @@ def validate_take_with_convert(convert, args, kwargs):


def validate_transpose_for_generic(inst, kwargs):
try:
Copy link
Member Author

Choose a reason for hiding this comment

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

This previously was only modifying the exception message for Panel objects before raising again, so I simplified to just remove the try...except altogether and let it raise as is

Copy link
Member

Choose a reason for hiding this comment

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

If it’s a one liner now, Is this still needed as a separate function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea could probably just call this directly now; I'll give it a look tonight and repush

validate_transpose(tuple(), kwargs)
except ValueError as e:
klass = type(inst).__name__
msg = str(e)

# the Panel class actual relies on the 'axes' parameter if called
# via the 'numpy' library, so let's make sure the error is specific
# about saying that the parameter is not supported for particular
# implementations of 'transpose'
if "the 'axes' parameter is not supported" in msg:
msg += " for {klass} instances".format(klass=klass)

raise ValueError(msg)
validate_transpose(tuple(), kwargs)


def validate_window_func(name, args, kwargs):
Expand Down
23 changes: 2 additions & 21 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,7 @@ def _constructor(self):

@property
def _constructor_expanddim(self):
# TODO: Raise NotImplementedError or change note in extending.rst
from pandas.core.panel import Panel
return Panel
raise NotImplementedError("Not supported for DataFrames!")
Copy link
Member Author

Choose a reason for hiding this comment

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

The TODO mentions changing the docs extending.rst but that looks to have already been done


# ----------------------------------------------------------------------
# Constructors
Expand Down Expand Up @@ -1934,22 +1932,6 @@ def to_sparse(self, fill_value=None, kind='block'):
columns=self.columns, default_kind=kind,
default_fill_value=fill_value)

def to_panel(self):
"""
Transform long (stacked) format (DataFrame) into wide (3D, Panel)
format.

.. deprecated:: 0.20.0

Currently the index of the DataFrame must be a 2-level MultiIndex. This
may be generalized later

Returns
-------
Panel
"""
raise NotImplementedError("Panel is being removed in pandas 0.25.0.")

@deprecate_kwarg(old_arg_name='encoding', new_arg_name=None)
def to_stata(self, fname, convert_dates=None, write_index=True,
encoding="latin-1", byteorder=None, time_stamp=None,
Expand Down Expand Up @@ -6630,8 +6612,7 @@ def append(self, other, ignore_index=False,

See Also
--------
concat : General function to concatenate DataFrame, Series
or Panel objects.
concat : General function to concatenate DataFrame or Series objects.

Notes
-----
Expand Down
41 changes: 15 additions & 26 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
is_dict_like, is_extension_array_dtype, is_integer, is_list_like,
is_number, is_numeric_dtype, is_object_dtype, is_period_arraylike,
is_re_compilable, is_scalar, is_timedelta64_dtype, pandas_dtype)
from pandas.core.dtypes.generic import ABCDataFrame, ABCPanel, ABCSeries
from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
from pandas.core.dtypes.inference import is_hashable
from pandas.core.dtypes.missing import isna, notna

Expand Down Expand Up @@ -978,7 +978,7 @@ def rename(self, *args, **kwargs):
----------
%(axes)s : scalar, list-like, dict-like or function, optional
Scalar or list-like will alter the ``Series.name`` attribute,
and raise on DataFrame or Panel.
and raise on DataFrame.
dict-like or functions are transformations to apply to
that axis' values
copy : bool, default True
Expand Down Expand Up @@ -1852,16 +1852,14 @@ def __iter__(self):
def keys(self):
"""Get the 'info axis' (see Indexing for more)

This is index for Series, columns for DataFrame and major_axis for
Panel.
This is index for Series, columns for DataFrame.
"""
return self._info_axis

def iteritems(self):
"""Iterate over (label, values) on info axis

This is index for Series, columns for DataFrame, major_axis for Panel,
and so on.
This is index for Series, columns for DataFrame and so on.
"""
for h in self._info_axis:
yield h, self[h]
Expand Down Expand Up @@ -3063,8 +3061,9 @@ def _create_indexer(cls, name, indexer):

def get(self, key, default=None):
"""
Get item from object for given key (DataFrame column, Panel slice,
etc.). Returns default value if not found.
Get item from object for given key (ex: DataFrame column).

Returns default value if not found.

Parameters
----------
Expand Down Expand Up @@ -4091,8 +4090,7 @@ def sort_values(self, by=None, axis=0, ascending=True, inplace=False,
0 A 2 0
1 A 1 1
"""
raise NotImplementedError("sort_values has not been implemented "
"on Panel or Panel4D objects.")
raise NotImplementedError("sort_values has not been implemented.")
Copy link
Member

Choose a reason for hiding this comment

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

Since this is now never hit, should this be AbstractMethodError?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea I think could go for that too


def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
kind='quicksort', na_position='last', sort_remaining=True):
Expand Down Expand Up @@ -4770,7 +4768,7 @@ def sample(self, n=None, frac=None, replace=False, weights=None,
object.
axis : int or string, optional
Axis to sample. Accepts axis number or name. Default is stat axis
for given data type (0 for Series and DataFrames, 1 for Panels).
for given data type (0 for Series and DataFrames).

Returns
-------
Expand Down Expand Up @@ -4853,7 +4851,7 @@ def sample(self, n=None, frac=None, replace=False, weights=None,
"a DataFrame")
else:
raise ValueError("Strings cannot be passed as weights "
"when sampling from a Series or Panel.")
"when sampling from a Series.")

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

Expand Down Expand Up @@ -5697,8 +5695,7 @@ def astype(self, dtype, copy=True, errors='raise', **kwargs):
elif self.ndim > 2:
raise NotImplementedError(
'astype() only accepts a dtype arg of type dict when '
'invoked on Series and DataFrames. A single dtype must be '
'specified when invoked on a Panel.'
'invoked on Series and DataFrames.'
)
for col_name in dtype.keys():
if col_name not in self:
Expand Down Expand Up @@ -5751,7 +5748,7 @@ def copy(self, deep=True):

Returns
-------
copy : Series, DataFrame or Panel
copy : Series or DataFrame
Object type matches caller.

Notes
Expand Down Expand Up @@ -6822,8 +6819,7 @@ 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 "
"on Panel and Panel 4D objects.")
raise NotImplementedError("Interpolate has not been implemented ")

if axis == 0:
ax = self._info_axis_name
Expand Down Expand Up @@ -7326,9 +7322,6 @@ def clip(self, lower=None, upper=None, axis=None, inplace=False,
3 6 8
4 5 3
"""
if isinstance(self, ABCPanel):
raise NotImplementedError("clip is not supported yet for panels")

inplace = validate_bool_kwarg(inplace, 'inplace')

axis = nv.validate_clip_with_axis(axis, args, kwargs)
Expand Down Expand Up @@ -8348,8 +8341,7 @@ def rank(self, axis=0, method='average', numeric_only=None,
* first: ranks assigned in order they appear in the array
* dense: like 'min', but rank always increases by 1 between groups
numeric_only : boolean, default None
Include only float, int, boolean data. Valid only for DataFrame or
Panel objects
Include only float, int, boolean data. Valid only for DataFrames.
na_option : {'keep', 'top', 'bottom'}
* keep: leave NA values where they are
* top: smallest rank if ascending
Expand Down Expand Up @@ -9773,10 +9765,7 @@ def describe(self, percentiles=None, include=None, exclude=None):
75% NaN 2.5
max NaN 3.0
"""
if self.ndim >= 3:
msg = "describe is not implemented on Panel objects."
raise NotImplementedError(msg)
elif self.ndim == 2 and self.columns.size == 0:
if self.ndim == 2 and self.columns.size == 0:
raise ValueError("Cannot describe a DataFrame without columns")

if percentiles is not None:
Expand Down
1 change: 0 additions & 1 deletion pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class providing the base-class of operations.
--------
Series.%(name)s
DataFrame.%(name)s
Panel.%(name)s
"""

_apply_docs = dict(
Expand Down
133 changes: 2 additions & 131 deletions pandas/core/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
is_integer_dtype, is_list_like, is_object_dtype, is_period_dtype,
is_scalar, is_timedelta64_dtype, needs_i8_conversion)
from pandas.core.dtypes.generic import (
ABCDataFrame, ABCIndex, ABCIndexClass, ABCPanel, ABCSeries, ABCSparseArray,
ABCDataFrame, ABCIndex, ABCIndexClass, ABCSeries, ABCSparseArray,
ABCSparseSeries)
from pandas.core.dtypes.missing import isna, notna

Expand Down Expand Up @@ -234,7 +234,7 @@ def _gen_eval_kwargs(name):
"""
kwargs = {}

# Series and Panel appear to only pass __add__, __radd__, ...
# Series appear to only pass __add__, __radd__, ...
# but DataFrame gets both these dunder names _and_ non-dunder names
# add, radd, ...
name = name.replace('__', '')
Expand Down Expand Up @@ -991,41 +991,6 @@ def _get_op_name(op, special):
C True False
"""

_flex_doc_PANEL = """
Return {desc} of series and other, element-wise (binary operator `{op_name}`).
Equivalent to ``{equiv}``.

Parameters
----------
other : DataFrame or Panel
axis : {{items, major_axis, minor_axis}}
Axis to broadcast over

Returns
-------
Panel

See Also
--------
Panel.{reverse}
"""


_agg_doc_PANEL = """
Wrapper method for {op_name}

Parameters
----------
other : DataFrame or Panel
axis : {{items, major_axis, minor_axis}}
Axis to broadcast over

Returns
-------
Panel
"""


def _make_flex_doc(op_name, typ):
"""
Make the appropriate substitutions for the given operation and class-typ
Expand Down Expand Up @@ -1457,12 +1422,6 @@ def _get_method_wrappers(cls):
arith_special = _arith_method_SPARSE_ARRAY
comp_special = _arith_method_SPARSE_ARRAY
bool_special = _arith_method_SPARSE_ARRAY
elif issubclass(cls, ABCPanel):
arith_flex = _flex_method_PANEL
comp_flex = _comp_method_PANEL
arith_special = _arith_method_PANEL
comp_special = _comp_method_PANEL
bool_special = _arith_method_PANEL
elif issubclass(cls, ABCDataFrame):
# Same for DataFrame and SparseDataFrame
arith_flex = _arith_method_FRAME
Expand Down Expand Up @@ -2295,94 +2254,6 @@ def f(self, other):
return f


# -----------------------------------------------------------------------------
# Panel

def _arith_method_PANEL(cls, op, special):
# work only for scalars
op_name = _get_op_name(op, special)

def f(self, other):
if not is_scalar(other):
raise ValueError('Simple arithmetic with {name} can only be '
'done with scalar values'
.format(name=self._constructor.__name__))

return self._combine(other, op)

f.__name__ = op_name
return f


def _comp_method_PANEL(cls, op, special):
str_rep = _get_opstr(op, cls)
op_name = _get_op_name(op, special)

def na_op(x, y):
import pandas.core.computation.expressions as expressions

try:
result = expressions.evaluate(op, str_rep, x, y)
except TypeError:
result = mask_cmp_op(x, y, op, np.ndarray)
return result

@Appender('Wrapper for comparison method {name}'.format(name=op_name))
def f(self, other, axis=None):
# Validate the axis parameter
if axis is not None:
self._get_axis_number(axis)

if isinstance(other, self._constructor):
return self._compare_constructor(other, na_op)
elif isinstance(other, (self._constructor_sliced, ABCDataFrame,
ABCSeries)):
raise Exception("input needs alignment for this object [{object}]"
.format(object=self._constructor))
else:
return self._combine_const(other, na_op)

f.__name__ = op_name

return f


def _flex_method_PANEL(cls, op, special):
str_rep = _get_opstr(op, cls)
op_name = _get_op_name(op, special)
eval_kwargs = _gen_eval_kwargs(op_name)
fill_zeros = _gen_fill_zeros(op_name)

def na_op(x, y):
import pandas.core.computation.expressions as expressions

try:
result = expressions.evaluate(op, str_rep, x, y,
errors='raise',
**eval_kwargs)
except TypeError:
result = op(x, y)

# handles discrepancy between numpy and numexpr on division/mod
# by 0 though, given that these are generally (always?)
# non-scalars, I'm not sure whether it's worth it at the moment
result = missing.fill_zeros(result, x, y, op_name, fill_zeros)
return result

if op_name in _op_descriptions:
doc = _make_flex_doc(op_name, 'panel')
else:
# doc strings substitors
doc = _agg_doc_PANEL.format(op_name=op_name)

@Appender(doc)
def f(self, other, axis=0):
return self._combine(other, na_op, axis=axis)

f.__name__ = op_name
return f


# -----------------------------------------------------------------------------
# Sparse

Expand Down
2 changes: 0 additions & 2 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,4 @@ def sort_values(self, *args, **kwargs):
'minor_axis': 'columns'},
docs={})

ops.add_special_arithmetic_methods(Panel)
ops.add_flex_arithmetic_methods(Panel)
Panel._add_numeric_operations()
2 changes: 1 addition & 1 deletion pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False,

Parameters
----------
objs : a sequence or mapping of Series, DataFrame, or Panel objects
objs : a sequence or mapping of Series or DataFrame objects.
If a dict is passed, the sorted keys will be used as the `keys`
argument, unless it is passed, in which case the values will be
selected (see below). Any None objects will be dropped silently unless
Expand Down
Loading