From f4c52e4ea377f899d2fe6cd8d6df59140fced59b Mon Sep 17 00:00:00 2001 From: Grant Smith Date: Sun, 4 Mar 2018 23:21:09 -0500 Subject: [PATCH 1/4] CLN: Deprecate Index.summary (GH18217) --- doc/source/whatsnew/v0.23.0.txt | 1 + pandas/core/frame.py | 8 ++++---- pandas/core/indexes/base.py | 11 ++++++++++- pandas/core/indexes/datetimelike.py | 11 ++++++++++- .../tests/indexes/datetimes/test_formats.py | 19 ++++++++++--------- pandas/tests/indexes/period/test_formats.py | 9 ++++++++- pandas/tests/indexes/test_base.py | 11 +++++++++-- .../tests/indexes/timedeltas/test_formats.py | 9 ++++++++- 8 files changed, 60 insertions(+), 19 deletions(-) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index 791365295c268..53b91e79f5477 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -736,6 +736,7 @@ Deprecations - :attr:`Timestamp.weekday_name`, :attr:`DatetimeIndex.weekday_name`, and :attr:`Series.dt.weekday_name` are deprecated in favor of :meth:`Timestamp.day_name`, :meth:`DatetimeIndex.day_name`, and :meth:`Series.dt.day_name` (:issue:`12806`) - ``pandas.tseries.plotting.tsplot`` is deprecated. Use :func:`Series.plot` instead (:issue:`18627`) +- ``Index.summary()`` is deprecated and will be removed in a future version (:issue:`18217`) .. _whatsnew_0230.prior_deprecations: diff --git a/pandas/core/frame.py b/pandas/core/frame.py index eaab17513aaf4..e884c91a29f91 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2005,7 +2005,7 @@ def info(self, verbose=None, buf=None, max_cols=None, memory_usage=None, lines = [] lines.append(str(type(self))) - lines.append(self.index.summary()) + lines.append(self.index._summary()) if len(self.columns) == 0: lines.append('Empty %s' % type(self).__name__) @@ -2341,7 +2341,7 @@ def __getitem__(self, key): try: if key in self.columns and not is_mi_columns: return self._getitem_column(key) - except: + except Exception: pass # see if we can slice the rows @@ -2843,7 +2843,7 @@ def _ensure_valid_index(self, value): if not len(self.index) and is_list_like(value): try: value = Series(value) - except: + except Exception: raise ValueError('Cannot set a frame with no defined index ' 'and a value that cannot be converted to a ' 'Series') @@ -6828,7 +6828,7 @@ def convert(v): values = np.array([convert(v) for v in values]) else: values = convert(values) - except: + except Exception: values = convert(values) else: diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index f69777af31c9c..b008d93b83371 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1385,7 +1385,7 @@ def _has_complex_internals(self): # to disable groupby tricks in MultiIndex return False - def summary(self, name=None): + def _summary(self, name=None): if len(self) > 0: head = self[0] if (hasattr(head, 'format') and @@ -1404,6 +1404,15 @@ def summary(self, name=None): name = type(self).__name__ return '%s: %s entries%s' % (name, len(self), index_summary) + def summary(self, name=None): + """ + .. deprecated:: 0.23.0 + No longer supported + """ + warnings.warn("'summary' is deprecated and will be removed in a " + "future version.", FutureWarning, stacklevel=2) + return self._summary(name) + def _mpl_repr(self): # how to represent ourselves to matplotlib return self.values diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 1be71ff68c2fb..9381e3a674580 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -1049,7 +1049,7 @@ def where(self, cond, other=None): return self._shallow_copy(result, **self._get_attributes_dict()) - def summary(self, name=None): + def _summary(self, name=None): """ return a summarized representation """ @@ -1071,6 +1071,15 @@ def summary(self, name=None): result = result.replace("'", "") return result + def summary(self, name=None): + """ + .. deprecated:: 0.23.0 + No longer supported + """ + warnings.warn("'summary' is deprecated and will be removed in a " + "future version.", FutureWarning, stacklevel=2) + return self._summary(name) + def _concat_same_dtype(self, to_concat, name): """ Concatenate to_concat which has the same class diff --git a/pandas/tests/indexes/datetimes/test_formats.py b/pandas/tests/indexes/datetimes/test_formats.py index 0d1a9e65ce6c6..63d5338d88d76 100644 --- a/pandas/tests/indexes/datetimes/test_formats.py +++ b/pandas/tests/indexes/datetimes/test_formats.py @@ -182,7 +182,7 @@ def test_dti_summary(self): for idx, expected in zip([idx1, idx2, idx3, idx4, idx5, idx6], [exp1, exp2, exp3, exp4, exp5, exp6]): - result = idx.summary() + result = idx._summary() assert result == expected def test_dti_business_repr(self): @@ -191,15 +191,15 @@ def test_dti_business_repr(self): def test_dti_business_summary(self): rng = pd.bdate_range(datetime(2009, 1, 1), datetime(2010, 1, 1)) - rng.summary() - rng[2:2].summary() + rng._summary() + rng[2:2]._summary() def test_dti_business_summary_pytz(self): - pd.bdate_range('1/1/2005', '1/1/2009', tz=pytz.utc).summary() + pd.bdate_range('1/1/2005', '1/1/2009', tz=pytz.utc)._summary() def test_dti_business_summary_dateutil(self): pd.bdate_range('1/1/2005', '1/1/2009', - tz=dateutil.tz.tzutc()).summary() + tz=dateutil.tz.tzutc())._summary() def test_dti_custom_business_repr(self): # only really care that it works @@ -209,12 +209,13 @@ def test_dti_custom_business_repr(self): def test_dti_custom_business_summary(self): rng = pd.bdate_range(datetime(2009, 1, 1), datetime(2010, 1, 1), freq='C') - rng.summary() - rng[2:2].summary() + rng._summary() + rng[2:2]._summary() def test_dti_custom_business_summary_pytz(self): - pd.bdate_range('1/1/2005', '1/1/2009', freq='C', tz=pytz.utc).summary() + pd.bdate_range('1/1/2005', '1/1/2009', freq='C', + tz=pytz.utc)._summary() def test_dti_custom_business_summary_dateutil(self): pd.bdate_range('1/1/2005', '1/1/2009', freq='C', - tz=dateutil.tz.tzutc()).summary() + tz=dateutil.tz.tzutc())._summary() diff --git a/pandas/tests/indexes/period/test_formats.py b/pandas/tests/indexes/period/test_formats.py index b1a1060bf86c4..fef92497cb512 100644 --- a/pandas/tests/indexes/period/test_formats.py +++ b/pandas/tests/indexes/period/test_formats.py @@ -205,5 +205,12 @@ def test_summary(self): idx6, idx7, idx8, idx9], [exp1, exp2, exp3, exp4, exp5, exp6, exp7, exp8, exp9]): - result = idx.summary() + result = idx._summary() assert result == expected + + def test_summary_deprecated(self): + # GH18217 + idx = PeriodIndex(['2011-01-01'], freq='D') + + with tm.assert_produces_warning(FutureWarning): + idx.summary() diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index e8f05cb928cad..b30cc4b012f14 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -1055,14 +1055,21 @@ def test_is_all_dates(self): assert not self.intIndex.is_all_dates def test_summary(self): - self._check_method_works(Index.summary) + self._check_method_works(Index._summary) # GH3869 ind = Index(['{other}%s', "~:{range}:0"], name='A') - result = ind.summary() + result = ind._summary() # shouldn't be formatted accidentally. assert '~:{range}:0' in result assert '{other}%s' in result + # GH18217 + def test_summary_deprecated(self): + ind = Index(['{other}%s', "~:{range}:0"], name='A') + + with tm.assert_produces_warning(FutureWarning): + ind.summary() + def test_format(self): self._check_method_works(Index.format) diff --git a/pandas/tests/indexes/timedeltas/test_formats.py b/pandas/tests/indexes/timedeltas/test_formats.py index a8375459d74e4..bc3de283f21dd 100644 --- a/pandas/tests/indexes/timedeltas/test_formats.py +++ b/pandas/tests/indexes/timedeltas/test_formats.py @@ -5,6 +5,8 @@ import pandas as pd from pandas import TimedeltaIndex +import pandas.util.testing as tm + class TestTimedeltaIndexRendering(object): @pytest.mark.parametrize('method', ['__repr__', '__unicode__', '__str__']) @@ -67,6 +69,11 @@ def test_representation_to_series(self): result = repr(pd.Series(idx)) assert result == expected + def test_summary_deprecated(self): + idx = TimedeltaIndex([], freq='D') + with tm.assert_produces_warning(FutureWarning): + idx.summary() + def test_summary(self): # GH#9116 idx1 = TimedeltaIndex([], freq='D') @@ -92,5 +99,5 @@ def test_summary(self): for idx, expected in zip([idx1, idx2, idx3, idx4, idx5], [exp1, exp2, exp3, exp4, exp5]): - result = idx.summary() + result = idx._summary() assert result == expected From 9be79850da8600bfb7eb50e210c2bdbf42fb610a Mon Sep 17 00:00:00 2001 From: Grant Smith Date: Tue, 13 Mar 2018 21:01:26 -0400 Subject: [PATCH 2/4] CLN: Deprecate Index.summary (GH18217) Review code changes --- pandas/core/frame.py | 6 +++--- pandas/core/indexes/base.py | 6 ++++++ pandas/core/indexes/datetimelike.py | 13 +++---------- pandas/tests/indexes/period/test_formats.py | 7 ------- pandas/tests/indexes/timedeltas/test_formats.py | 7 ------- 5 files changed, 12 insertions(+), 27 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index e884c91a29f91..7dbfd0f733496 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2341,7 +2341,7 @@ def __getitem__(self, key): try: if key in self.columns and not is_mi_columns: return self._getitem_column(key) - except Exception: + except: pass # see if we can slice the rows @@ -2843,7 +2843,7 @@ def _ensure_valid_index(self, value): if not len(self.index) and is_list_like(value): try: value = Series(value) - except Exception: + except: raise ValueError('Cannot set a frame with no defined index ' 'and a value that cannot be converted to a ' 'Series') @@ -6828,7 +6828,7 @@ def convert(v): values = np.array([convert(v) for v in values]) else: values = convert(values) - except Exception: + except: values = convert(values) else: diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index b008d93b83371..c9b7d5a3bdf8a 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1386,6 +1386,11 @@ def _has_complex_internals(self): return False def _summary(self, name=None): + """ + Return a summarized representation + .. deprecated:: 0.23.0 + No longer supported + """ if len(self) > 0: head = self[0] if (hasattr(head, 'format') and @@ -1406,6 +1411,7 @@ def _summary(self, name=None): def summary(self, name=None): """ + Return a summarized representation .. deprecated:: 0.23.0 No longer supported """ diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 9381e3a674580..3e9a1f7fdd1fb 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -1051,7 +1051,9 @@ def where(self, cond, other=None): def _summary(self, name=None): """ - return a summarized representation + Return a summarized representation + .. deprecated:: 0.23.0 + No longer supported """ formatter = self._formatter_func if len(self) > 0: @@ -1071,15 +1073,6 @@ def _summary(self, name=None): result = result.replace("'", "") return result - def summary(self, name=None): - """ - .. deprecated:: 0.23.0 - No longer supported - """ - warnings.warn("'summary' is deprecated and will be removed in a " - "future version.", FutureWarning, stacklevel=2) - return self._summary(name) - def _concat_same_dtype(self, to_concat, name): """ Concatenate to_concat which has the same class diff --git a/pandas/tests/indexes/period/test_formats.py b/pandas/tests/indexes/period/test_formats.py index fef92497cb512..c3926cc5f1633 100644 --- a/pandas/tests/indexes/period/test_formats.py +++ b/pandas/tests/indexes/period/test_formats.py @@ -207,10 +207,3 @@ def test_summary(self): exp6, exp7, exp8, exp9]): result = idx._summary() assert result == expected - - def test_summary_deprecated(self): - # GH18217 - idx = PeriodIndex(['2011-01-01'], freq='D') - - with tm.assert_produces_warning(FutureWarning): - idx.summary() diff --git a/pandas/tests/indexes/timedeltas/test_formats.py b/pandas/tests/indexes/timedeltas/test_formats.py index bc3de283f21dd..09921fac80d22 100644 --- a/pandas/tests/indexes/timedeltas/test_formats.py +++ b/pandas/tests/indexes/timedeltas/test_formats.py @@ -5,8 +5,6 @@ import pandas as pd from pandas import TimedeltaIndex -import pandas.util.testing as tm - class TestTimedeltaIndexRendering(object): @pytest.mark.parametrize('method', ['__repr__', '__unicode__', '__str__']) @@ -69,11 +67,6 @@ def test_representation_to_series(self): result = repr(pd.Series(idx)) assert result == expected - def test_summary_deprecated(self): - idx = TimedeltaIndex([], freq='D') - with tm.assert_produces_warning(FutureWarning): - idx.summary() - def test_summary(self): # GH#9116 idx1 = TimedeltaIndex([], freq='D') From c280bede95afefa1b3e8849e56610c2ffd797208 Mon Sep 17 00:00:00 2001 From: Grant Smith Date: Wed, 14 Mar 2018 19:38:10 -0400 Subject: [PATCH 3/4] CLN: Deprecate Index.summary (GH18217) Update docstrings --- pandas/core/indexes/base.py | 11 +++++++++-- pandas/core/indexes/datetimelike.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index c9b7d5a3bdf8a..4156fe9d83baa 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1388,8 +1388,15 @@ def _has_complex_internals(self): def _summary(self, name=None): """ Return a summarized representation - .. deprecated:: 0.23.0 - No longer supported + + Parameters + ---------- + name : str + name to use in the summary representation + + Returns + ------- + String with a summarized representation of the index """ if len(self) > 0: head = self[0] diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 3e9a1f7fdd1fb..b3372859a116c 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -1052,8 +1052,15 @@ def where(self, cond, other=None): def _summary(self, name=None): """ Return a summarized representation - .. deprecated:: 0.23.0 - No longer supported + + Parameters + ---------- + name : str + name to use in the summary representation + + Returns + ------- + String with a summarized representation of the index """ formatter = self._formatter_func if len(self) > 0: From ccb33cb0878b5312a4e3ea8f3daf3fe69bb844a1 Mon Sep 17 00:00:00 2001 From: Grant Smith Date: Thu, 15 Mar 2018 19:44:46 -0400 Subject: [PATCH 4/4] CLN: Deprecate Index.summary (GH18217) Minor docstring tweaks --- pandas/core/indexes/base.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 4156fe9d83baa..a7acd58d8d19e 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1420,7 +1420,6 @@ def summary(self, name=None): """ Return a summarized representation .. deprecated:: 0.23.0 - No longer supported """ warnings.warn("'summary' is deprecated and will be removed in a " "future version.", FutureWarning, stacklevel=2)