From 848e262823f4ea3c28ee4abf493437a6b87f16e7 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 12 Mar 2019 12:44:37 +0000 Subject: [PATCH] CLN: remove Panel from concat error message (#25676) --- pandas/core/reshape/concat.py | 8 ++--- pandas/tests/reshape/test_concat.py | 45 +++++------------------------ 2 files changed, 11 insertions(+), 42 deletions(-) diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index a6c945ac2e464..6cc355fb62f23 100644 --- a/pandas/core/reshape/concat.py +++ b/pandas/core/reshape/concat.py @@ -282,10 +282,10 @@ def __init__(self, objs, axis=0, join='outer', join_axes=None, # consolidate data & figure out what our result ndim is going to be ndims = set() for obj in objs: - if not isinstance(obj, NDFrame): - msg = ('cannot concatenate object of type "{0}";' - ' only pd.Series, pd.DataFrame, and pd.Panel' - ' (deprecated) objs are valid'.format(type(obj))) + if not isinstance(obj, (Series, DataFrame)): + msg = ("cannot concatenate object of type '{}';" + ' only Series and DataFrame objs are valid' + .format(type(obj))) raise TypeError(msg) # consolidate diff --git a/pandas/tests/reshape/test_concat.py b/pandas/tests/reshape/test_concat.py index a186d32ed8800..9dbc14c23f3f4 100644 --- a/pandas/tests/reshape/test_concat.py +++ b/pandas/tests/reshape/test_concat.py @@ -16,7 +16,7 @@ import pandas as pd from pandas import ( - Categorical, DataFrame, DatetimeIndex, Index, MultiIndex, Panel, Series, + Categorical, DataFrame, DatetimeIndex, Index, MultiIndex, Series, Timestamp, concat, date_range, isna, read_csv) from pandas.tests.extension.decimal import to_decimal from pandas.util import testing as tm @@ -196,9 +196,8 @@ def test_concatlike_same_dtypes(self): tm.assert_series_equal(res, exp, check_index_type=True) # cannot append non-index - msg = (r'cannot concatenate object of type \"(.+?)\";' - ' only pd.Series, pd.DataFrame, and pd.Panel' - r' \(deprecated\) objs are valid') + msg = (r"cannot concatenate object of type '.+';" + " only Series and DataFrame objs are valid") with pytest.raises(TypeError, match=msg): pd.Series(vals1).append(vals2) @@ -1534,33 +1533,6 @@ def test_dtype_coerceion(self): result = concat([df.iloc[[0]], df.iloc[[1]]]) tm.assert_series_equal(result.dtypes, df.dtypes) - @pytest.mark.filterwarnings("ignore:\\nPanel:FutureWarning") - # Panel.rename warning we don't care about - @pytest.mark.filterwarnings("ignore:Using:FutureWarning") - def test_panel_concat_buglet(self, sort): - # #2257 - def make_panel(): - index = 5 - cols = 3 - - def df(): - return DataFrame(np.random.randn(index, cols), - index=["I%s" % i for i in range(index)], - columns=["C%s" % i for i in range(cols)]) - return Panel({"Item%s" % x: df() for x in ['A', 'B', 'C']}) - - panel1 = make_panel() - panel2 = make_panel() - - panel2 = panel2.rename(major_axis={x: "%s_1" % x - for x in panel2.major_axis}) - - panel3 = panel2.rename(major_axis=lambda x: '%s_1' % x) - panel3 = panel3.rename(minor_axis=lambda x: '%s_1' % x) - - # it works! - concat([panel1, panel3], axis=1, verify_integrity=True, sort=sort) - def test_concat_series(self): ts = tm.makeTimeSeries() @@ -1781,9 +1753,8 @@ def test_concat_invalid(self): # trying to concat a ndframe with a non-ndframe df1 = mkdf(10, 2) - msg = ('cannot concatenate object of type "{}";' - ' only pd.Series, pd.DataFrame, and pd.Panel' - r' \(deprecated\) objs are valid') + msg = ("cannot concatenate object of type '{}';" + " only Series and DataFrame objs are valid") for obj in [1, dict(), [1, 2], (1, 2)]: with pytest.raises(TypeError, match=msg.format(type(obj))): concat([df1, obj]) @@ -2400,9 +2371,8 @@ def test_concat_different_extension_dtypes_upcasts(self): tm.assert_series_equal(result, expected) -@pytest.mark.parametrize('pdt', [pd.Series, pd.DataFrame, pd.Panel]) +@pytest.mark.parametrize('pdt', [pd.Series, pd.DataFrame]) @pytest.mark.parametrize('dt', np.sctypes['float']) -@pytest.mark.filterwarnings("ignore:\\nPanel:FutureWarning") def test_concat_no_unnecessary_upcast(dt, pdt): # GH 13247 dims = pdt().ndim @@ -2413,9 +2383,8 @@ def test_concat_no_unnecessary_upcast(dt, pdt): assert x.values.dtype == dt -@pytest.mark.parametrize('pdt', [pd.Series, pd.DataFrame, pd.Panel]) +@pytest.mark.parametrize('pdt', [pd.Series, pd.DataFrame]) @pytest.mark.parametrize('dt', np.sctypes['int']) -@pytest.mark.filterwarnings("ignore:\\nPanel:FutureWarning") def test_concat_will_upcast(dt, pdt): with catch_warnings(record=True): dims = pdt().ndim