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

remove panel conversion #3845

Merged
merged 1 commit into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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 @@ -3403,14 +3403,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