Skip to content

Commit

Permalink
remove panel conversion (#3845)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty authored Mar 9, 2020
1 parent 603b0ad commit 203c3f4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ Internal Changes
By `Bruno Pagani <https://github.com/ArchangeGabriel>`_.
- Updated Azure CI MacOS image, given pending removal.
By `Maximilian Roos <https://github.com/max-sixty>`_
- Removed conversion to :py:class:`pandas.Panel`, given its removal in pandas
in favor of xarray's objects.
By `Maximilian Roos <https://github.com/max-sixty>`_

.. _whats-new.0.15.0:

Expand Down
10 changes: 2 additions & 8 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2243,20 +2243,14 @@ def to_pandas(self) -> Union["DataArray", pd.Series, pd.DataFrame]:
* 0D -> `xarray.DataArray`
* 1D -> `pandas.Series`
* 2D -> `pandas.DataFrame`
* 3D -> `pandas.Panel` *(deprecated)*
Only works for arrays with 3 or fewer dimensions.
Only works for arrays with 2 or fewer dimensions.
The DataArray constructor performs the inverse transformation.
"""
# TODO: consolidate the info about pandas constructors and the
# attributes that correspond to their indexes into a separate module?
constructors = {
0: lambda x: x,
1: pd.Series,
2: pd.DataFrame,
3: pdcompat.Panel,
}
constructors = {0: lambda x: x, 1: pd.Series, 2: pd.DataFrame}
try:
constructor = constructors[self.ndim]
except KeyError:
Expand Down
8 changes: 2 additions & 6 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -3411,14 +3411,10 @@ def test_to_pandas(self):
assert_array_equal(actual.columns, [0, 1])

# roundtrips
for shape in [(3,), (3, 4), (3, 4, 5)]:
if len(shape) > 2 and LooseVersion(pd.__version__) >= "0.25.0":
continue
for shape in [(3,), (3, 4)]:
dims = list("abc")[: len(shape)]
da = DataArray(np.random.randn(*shape), dims=dims)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", r"\W*Panel is deprecated")
roundtripped = DataArray(da.to_pandas()).drop_vars(dims)
roundtripped = DataArray(da.to_pandas()).drop_vars(dims)
assert_identical(da, roundtripped)

with raises_regex(ValueError, "cannot convert"):
Expand Down

0 comments on commit 203c3f4

Please sign in to comment.