Skip to content
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

CLN: Panel reference from documentation #25649

Merged
merged 14 commits into from
Mar 20, 2019
7 changes: 0 additions & 7 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import inspect
import importlib
import logging
import warnings
import jinja2
from sphinx.ext.autosummary import _import_by_name
from numpydoc.docscrape import NumpyDocString
Expand Down Expand Up @@ -412,12 +411,6 @@
'wiki ')}


# ignore all deprecation warnings from Panel during doc build
# (to avoid the need to add :okwarning: in many places)
warnings.filterwarnings("ignore", message="\nPanel is deprecated",
category=FutureWarning)


ipython_warning_is_error = False
ipython_exec_lines = [
'import numpy as np',
Expand Down
4 changes: 2 additions & 2 deletions doc/source/development/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ There are 3 constructor properties to be defined:

* ``_constructor``: Used when a manipulation result has the same dimensions as the original.
* ``_constructor_sliced``: Used when a manipulation result has one lower dimension(s) as the original, such as ``DataFrame`` single columns slicing.
* ``_constructor_expanddim``: Used when a manipulation result has one higher dimension as the original, such as ``Series.to_frame()`` and ``DataFrame.to_panel()``.
* ``_constructor_expanddim``: Used when a manipulation result has one higher dimension as the original, such as ``Series.to_frame()``.

Following table shows how ``pandas`` data structures define constructor properties by default.

Expand All @@ -280,7 +280,7 @@ Property Attributes ``Series`` ``DataFrame``
=========================== ======================= =============
``_constructor`` ``Series`` ``DataFrame``
``_constructor_sliced`` ``NotImplementedError`` ``Series``
``_constructor_expanddim`` ``DataFrame`` ``Panel``
``_constructor_expanddim`` ``DataFrame`` ``NotImplementedError``
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 is not true yet, but I would think this would raise a NotImplementedError once panel is removed?

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense to me. FYI there's a call above this for to_panel I imagine we want to remove

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch. Removed.

=========================== ======================= =============

Below example shows how to define ``SubclassedSeries`` and ``SubclassedDataFrame`` overriding constructor properties.
Expand Down
2 changes: 1 addition & 1 deletion doc/source/ecosystem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Pandas DataFrames with timeseries indexes.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PyDatastream is a Python interface to the
`Thomson Dataworks Enterprise (DWE/Datastream) <http://dataworks.thomson.com/Dataworks/Enterprise/1.0/>`__
SOAP API to return indexed Pandas DataFrames or Panels with financial data.
SOAP API to return indexed Pandas DataFrames with financial data.
This package requires valid credentials for this API (non free).

`pandaSDMX <https://pandasdmx.readthedocs.io>`__
Expand Down
4 changes: 2 additions & 2 deletions doc/source/getting_started/10min.rst
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ Merge
Concat
~~~~~~

pandas provides various facilities for easily combining together Series,
DataFrame, and Panel objects with various kinds of set logic for the indexes
pandas provides various facilities for easily combining together Series and
DataFrame objects with various kinds of set logic for the indexes
and relational algebra functionality in the case of join / merge-type
operations.

Expand Down
38 changes: 5 additions & 33 deletions doc/source/getting_started/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ the previous section:
s = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd', 'e'])
df = pd.DataFrame(np.random.randn(8, 3), index=index,
columns=['A', 'B', 'C'])
wp = pd.Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
major_axis=pd.date_range('1/1/2000', periods=5),
minor_axis=['A', 'B', 'C', 'D'])
.. _basics.head_tail:

Expand Down Expand Up @@ -46,7 +43,6 @@ pandas objects have a number of attributes enabling you to access the metadata
* Axis labels
* **Series**: *index* (only axis)
* **DataFrame**: *index* (rows) and *columns*
* **Panel**: *items*, *major_axis*, and *minor_axis*

Note, **these attributes can be safely assigned to**!

Expand Down Expand Up @@ -118,7 +114,7 @@ columns, :meth:`DataFrame.to_numpy` will return the underlying data:
df.to_numpy()
If a DataFrame or Panel contains homogeneously-typed data, the ndarray can
If a DataFrame contains homogeneously-typed data, the ndarray can
actually be modified in-place, and the changes will be reflected in the data
structure. For heterogeneous data (e.g. some of the DataFrame's columns are not
all the same dtype), this will not be the case. The values attribute itself,
Expand Down Expand Up @@ -239,26 +235,6 @@ Furthermore you can align a level of a MultiIndexed DataFrame with a Series.
names=['first', 'second'])
dfmi.sub(column, axis=0, level='second')
With Panel, describing the matching behavior is a bit more difficult, so
the arithmetic methods instead (and perhaps confusingly?) give you the option
to specify the *broadcast axis*. For example, suppose we wished to demean the
data over a particular axis. This can be accomplished by taking the mean over
an axis and broadcasting over the same axis:

.. ipython:: python
major_mean = wp.mean(axis='major')
major_mean
wp.sub(major_mean, axis='major')
And similarly for ``axis="items"`` and ``axis="minor"``.

.. note::

I could be convinced to make the **axis** argument in the DataFrame methods
match the broadcasting behavior of Panel. Though it would require a
transition period so users can change their code...

Series and Index also support the :func:`divmod` builtin. This function takes
the floor division and modulo operation at the same time returning a two-tuple
of the same type as the left hand side. For example:
Expand Down Expand Up @@ -407,7 +383,7 @@ This is because NaNs do not compare as equals:
np.nan == np.nan
So, NDFrames (such as Series, DataFrames, and Panels)
So, NDFrames (such as Series and DataFrames)
have an :meth:`~DataFrame.equals` method for testing equality, with NaNs in
corresponding locations treated as equal.

Expand Down Expand Up @@ -515,7 +491,7 @@ Descriptive statistics

There exists a large number of methods for computing descriptive statistics and
other related operations on :ref:`Series <api.series.stats>`, :ref:`DataFrame
<api.dataframe.stats>`, and :ref:`Panel <api.panel.stats>`. Most of these
<api.dataframe.stats>`. Most of these
are aggregations (hence producing a lower-dimensional result) like
:meth:`~DataFrame.sum`, :meth:`~DataFrame.mean`, and :meth:`~DataFrame.quantile`,
but some of them, like :meth:`~DataFrame.cumsum` and :meth:`~DataFrame.cumprod`,
Expand All @@ -525,8 +501,6 @@ specified by name or integer:

* **Series**: no axis argument needed
* **DataFrame**: "index" (axis=0, default), "columns" (axis=1)
* **Panel**: "items" (axis=0), "major" (axis=1, default), "minor"
(axis=2)

For example:

Expand Down Expand Up @@ -1481,15 +1455,14 @@ Iteration

The behavior of basic iteration over pandas objects depends on the type.
When iterating over a Series, it is regarded as array-like, and basic iteration
produces the values. Other data structures, like DataFrame and Panel,
produces the values. Other data structures, like DataFrame,
follow the dict-like convention of iterating over the "keys" of the
objects.

In short, basic iteration (``for i in object``) produces:

* **Series**: values
* **DataFrame**: column labels
* **Panel**: item labels

Thus, for example, iterating over a DataFrame gives you the column names:

Expand Down Expand Up @@ -1559,13 +1532,12 @@ through key-value pairs:

* **Series**: (index, scalar value) pairs
* **DataFrame**: (column, Series) pairs
* **Panel**: (item, DataFrame) pairs

For example:

.. ipython:: python
for item, frame in wp.iteritems():
for item, frame in df.iteritems():
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense though was this not failing CI before?

Copy link
Member Author

Choose a reason for hiding this comment

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

wp was a Panel defined beforehand (now removed).

print(item)
print(frame)
Expand Down
183 changes: 0 additions & 183 deletions doc/source/getting_started/dsintro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -847,186 +847,3 @@ completion mechanism so they can be tab-completed:
In [5]: df.fo<TAB> # noqa: E225, E999
df.foo1 df.foo2
.. _basics.panel:

Panel
-----

.. warning::

In 0.20.0, ``Panel`` is deprecated and will be removed in
a future version. See the section :ref:`Deprecate Panel <dsintro.deprecate_panel>`.

Panel is a somewhat less-used, but still important container for 3-dimensional
data. The term `panel data <https://en.wikipedia.org/wiki/Panel_data>`__ is
derived from econometrics and is partially responsible for the name pandas:
pan(el)-da(ta)-s. The names for the 3 axes are intended to give some semantic
meaning to describing operations involving panel data and, in particular,
econometric analysis of panel data. However, for the strict purposes of slicing
and dicing a collection of DataFrame objects, you may find the axis names
slightly arbitrary:

* **items**: axis 0, each item corresponds to a DataFrame contained inside
* **major_axis**: axis 1, it is the **index** (rows) of each of the
DataFrames
* **minor_axis**: axis 2, it is the **columns** of each of the DataFrames

Construction of Panels works about like you would expect:

From 3D ndarray with optional axis labels
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. ipython:: python
:okwarning:
wp = pd.Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
major_axis=pd.date_range('1/1/2000', periods=5),
minor_axis=['A', 'B', 'C', 'D'])
wp
From dict of DataFrame objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. ipython:: python
:okwarning:
data = {'Item1': pd.DataFrame(np.random.randn(4, 3)),
'Item2': pd.DataFrame(np.random.randn(4, 2))}
pd.Panel(data)
Note that the values in the dict need only be **convertible to
DataFrame**. Thus, they can be any of the other valid inputs to DataFrame as
per above.

One helpful factory method is ``Panel.from_dict``, which takes a
dictionary of DataFrames as above, and the following named parameters:

.. csv-table::
:header: "Parameter", "Default", "Description"
:widths: 10, 10, 40

intersect, ``False``, drops elements whose indices do not align
orient, ``items``, use ``minor`` to use DataFrames' columns as panel items

For example, compare to the construction above:

.. ipython:: python
:okwarning:
pd.Panel.from_dict(data, orient='minor')
Orient is especially useful for mixed-type DataFrames. If you pass a dict of
DataFrame objects with mixed-type columns, all of the data will get upcasted to
``dtype=object`` unless you pass ``orient='minor'``:

.. ipython:: python
:okwarning:
df = pd.DataFrame({'a': ['foo', 'bar', 'baz'],
'b': np.random.randn(3)})
df
data = {'item1': df, 'item2': df}
panel = pd.Panel.from_dict(data, orient='minor')
panel['a']
panel['b']
panel['b'].dtypes
.. note::

Panel, being less commonly used than Series and DataFrame,
has been slightly neglected feature-wise. A number of methods and options
available in DataFrame are not available in Panel.

.. _dsintro.to_panel:

From DataFrame using ``to_panel`` method
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

``to_panel`` converts a DataFrame with a two-level index to a Panel.

.. ipython:: python
:okwarning:
midx = pd.MultiIndex(levels=[['one', 'two'], ['x', 'y']],
codes=[[1, 1, 0, 0], [1, 0, 1, 0]])
df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [5, 6, 7, 8]}, index=midx)
df.to_panel()
.. _dsintro.panel_item_selection:

Item selection / addition / deletion
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Similar to DataFrame functioning as a dict of Series, Panel is like a dict
of DataFrames:

.. ipython:: python
wp['Item1']
wp['Item3'] = wp['Item1'] / wp['Item2']
The API for insertion and deletion is the same as for DataFrame. And as with
DataFrame, if the item is a valid Python identifier, you can access it as an
attribute and tab-complete it in IPython.

Transposing
~~~~~~~~~~~

A Panel can be rearranged using its ``transpose`` method (which does not make a
copy by default unless the data are heterogeneous):

.. ipython:: python
:okwarning:
wp.transpose(2, 0, 1)
Indexing / Selection
~~~~~~~~~~~~~~~~~~~~

.. csv-table::
:header: "Operation", "Syntax", "Result"
:widths: 30, 20, 10

Select item, ``wp[item]``, DataFrame
Get slice at major_axis label, ``wp.major_xs(val)``, DataFrame
Get slice at minor_axis label, ``wp.minor_xs(val)``, DataFrame

For example, using the earlier example data, we could do:

.. ipython:: python
wp['Item1']
wp.major_xs(wp.major_axis[2])
wp.minor_axis
wp.minor_xs('C')
Squeezing
~~~~~~~~~

Another way to change the dimensionality of an object is to ``squeeze`` a 1-len
object, similar to ``wp['Item1']``.

.. ipython:: python
:okwarning:
wp.reindex(items=['Item1']).squeeze()
wp.reindex(items=['Item1'], minor=['B']).squeeze()
Conversion to DataFrame
~~~~~~~~~~~~~~~~~~~~~~~

A Panel can be represented in 2D form as a hierarchically indexed
DataFrame. See the section :ref:`hierarchical indexing <advanced.hierarchical>`
for more on this. To convert a Panel to a DataFrame, use the ``to_frame``
method:

.. ipython:: python
:okwarning:
panel = pd.Panel(np.random.randn(3, 5, 4), items=['one', 'two', 'three'],
major_axis=pd.date_range('1/1/2000', periods=5),
minor_axis=['a', 'b', 'c', 'd'])
panel.to_frame()
2 changes: 1 addition & 1 deletion doc/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ Optional Dependencies
* `Cython <http://www.cython.org>`__: Only necessary to build development
version. Version 0.28.2 or higher.
* `SciPy <http://www.scipy.org>`__: miscellaneous statistical functions, Version 0.18.1 or higher
* `xarray <http://xarray.pydata.org>`__: pandas like handling for > 2 dims, needed for converting Panels to xarray objects. Version 0.7.0 or higher is recommended.
* `xarray <http://xarray.pydata.org>`__: pandas like handling for > 2 dims. Version 0.7.0 or higher is recommended.
* `PyTables <http://www.pytables.org>`__: necessary for HDF5-based storage, Version 3.4.2 or higher
* `pyarrow <http://arrow.apache.org/docs/python/>`__ (>= 0.9.0): necessary for feather-based storage.
* `Apache Parquet <https://parquet.apache.org/>`__, either `pyarrow <http://arrow.apache.org/docs/python/>`__ (>= 0.7.0) or `fastparquet <https://fastparquet.readthedocs.io/en/latest>`__ (>= 0.2.1) for parquet-based storage. The `snappy <https://pypi.org/project/python-snappy>`__ and `brotli <https://pypi.org/project/brotlipy>`__ are available for compression support.
Expand Down
9 changes: 0 additions & 9 deletions doc/source/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ public functions related to data types in pandas.
api/pandas.Index.is_type_compatible
api/pandas.Index.nlevels
api/pandas.Index.sort
api/pandas.Panel.agg
api/pandas.Panel.aggregate
api/pandas.Panel.blocks
api/pandas.Panel.empty
api/pandas.Panel.is_copy
api/pandas.Panel.items
api/pandas.Panel.ix
api/pandas.Panel.major_axis
api/pandas.Panel.minor_axis
api/pandas.Series.asobject
api/pandas.Series.blocks
api/pandas.Series.from_array
Expand Down
Loading