Skip to content

Commit f4c52e4

Browse files
committed
CLN: Deprecate Index.summary (GH18217)
1 parent 3783ccc commit f4c52e4

File tree

8 files changed

+60
-19
lines changed

8 files changed

+60
-19
lines changed

doc/source/whatsnew/v0.23.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ Deprecations
736736
- :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`)
737737

738738
- ``pandas.tseries.plotting.tsplot`` is deprecated. Use :func:`Series.plot` instead (:issue:`18627`)
739+
- ``Index.summary()`` is deprecated and will be removed in a future version (:issue:`18217`)
739740

740741
.. _whatsnew_0230.prior_deprecations:
741742

pandas/core/frame.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,7 +2005,7 @@ def info(self, verbose=None, buf=None, max_cols=None, memory_usage=None,
20052005
lines = []
20062006

20072007
lines.append(str(type(self)))
2008-
lines.append(self.index.summary())
2008+
lines.append(self.index._summary())
20092009

20102010
if len(self.columns) == 0:
20112011
lines.append('Empty %s' % type(self).__name__)
@@ -2341,7 +2341,7 @@ def __getitem__(self, key):
23412341
try:
23422342
if key in self.columns and not is_mi_columns:
23432343
return self._getitem_column(key)
2344-
except:
2344+
except Exception:
23452345
pass
23462346

23472347
# see if we can slice the rows
@@ -2843,7 +2843,7 @@ def _ensure_valid_index(self, value):
28432843
if not len(self.index) and is_list_like(value):
28442844
try:
28452845
value = Series(value)
2846-
except:
2846+
except Exception:
28472847
raise ValueError('Cannot set a frame with no defined index '
28482848
'and a value that cannot be converted to a '
28492849
'Series')
@@ -6828,7 +6828,7 @@ def convert(v):
68286828
values = np.array([convert(v) for v in values])
68296829
else:
68306830
values = convert(values)
6831-
except:
6831+
except Exception:
68326832
values = convert(values)
68336833

68346834
else:

pandas/core/indexes/base.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ def _has_complex_internals(self):
13851385
# to disable groupby tricks in MultiIndex
13861386
return False
13871387

1388-
def summary(self, name=None):
1388+
def _summary(self, name=None):
13891389
if len(self) > 0:
13901390
head = self[0]
13911391
if (hasattr(head, 'format') and
@@ -1404,6 +1404,15 @@ def summary(self, name=None):
14041404
name = type(self).__name__
14051405
return '%s: %s entries%s' % (name, len(self), index_summary)
14061406

1407+
def summary(self, name=None):
1408+
"""
1409+
.. deprecated:: 0.23.0
1410+
No longer supported
1411+
"""
1412+
warnings.warn("'summary' is deprecated and will be removed in a "
1413+
"future version.", FutureWarning, stacklevel=2)
1414+
return self._summary(name)
1415+
14071416
def _mpl_repr(self):
14081417
# how to represent ourselves to matplotlib
14091418
return self.values

pandas/core/indexes/datetimelike.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ def where(self, cond, other=None):
10491049
return self._shallow_copy(result,
10501050
**self._get_attributes_dict())
10511051

1052-
def summary(self, name=None):
1052+
def _summary(self, name=None):
10531053
"""
10541054
return a summarized representation
10551055
"""
@@ -1071,6 +1071,15 @@ def summary(self, name=None):
10711071
result = result.replace("'", "")
10721072
return result
10731073

1074+
def summary(self, name=None):
1075+
"""
1076+
.. deprecated:: 0.23.0
1077+
No longer supported
1078+
"""
1079+
warnings.warn("'summary' is deprecated and will be removed in a "
1080+
"future version.", FutureWarning, stacklevel=2)
1081+
return self._summary(name)
1082+
10741083
def _concat_same_dtype(self, to_concat, name):
10751084
"""
10761085
Concatenate to_concat which has the same class

pandas/tests/indexes/datetimes/test_formats.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def test_dti_summary(self):
182182

183183
for idx, expected in zip([idx1, idx2, idx3, idx4, idx5, idx6],
184184
[exp1, exp2, exp3, exp4, exp5, exp6]):
185-
result = idx.summary()
185+
result = idx._summary()
186186
assert result == expected
187187

188188
def test_dti_business_repr(self):
@@ -191,15 +191,15 @@ def test_dti_business_repr(self):
191191

192192
def test_dti_business_summary(self):
193193
rng = pd.bdate_range(datetime(2009, 1, 1), datetime(2010, 1, 1))
194-
rng.summary()
195-
rng[2:2].summary()
194+
rng._summary()
195+
rng[2:2]._summary()
196196

197197
def test_dti_business_summary_pytz(self):
198-
pd.bdate_range('1/1/2005', '1/1/2009', tz=pytz.utc).summary()
198+
pd.bdate_range('1/1/2005', '1/1/2009', tz=pytz.utc)._summary()
199199

200200
def test_dti_business_summary_dateutil(self):
201201
pd.bdate_range('1/1/2005', '1/1/2009',
202-
tz=dateutil.tz.tzutc()).summary()
202+
tz=dateutil.tz.tzutc())._summary()
203203

204204
def test_dti_custom_business_repr(self):
205205
# only really care that it works
@@ -209,12 +209,13 @@ def test_dti_custom_business_repr(self):
209209
def test_dti_custom_business_summary(self):
210210
rng = pd.bdate_range(datetime(2009, 1, 1), datetime(2010, 1, 1),
211211
freq='C')
212-
rng.summary()
213-
rng[2:2].summary()
212+
rng._summary()
213+
rng[2:2]._summary()
214214

215215
def test_dti_custom_business_summary_pytz(self):
216-
pd.bdate_range('1/1/2005', '1/1/2009', freq='C', tz=pytz.utc).summary()
216+
pd.bdate_range('1/1/2005', '1/1/2009', freq='C',
217+
tz=pytz.utc)._summary()
217218

218219
def test_dti_custom_business_summary_dateutil(self):
219220
pd.bdate_range('1/1/2005', '1/1/2009', freq='C',
220-
tz=dateutil.tz.tzutc()).summary()
221+
tz=dateutil.tz.tzutc())._summary()

pandas/tests/indexes/period/test_formats.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,12 @@ def test_summary(self):
205205
idx6, idx7, idx8, idx9],
206206
[exp1, exp2, exp3, exp4, exp5,
207207
exp6, exp7, exp8, exp9]):
208-
result = idx.summary()
208+
result = idx._summary()
209209
assert result == expected
210+
211+
def test_summary_deprecated(self):
212+
# GH18217
213+
idx = PeriodIndex(['2011-01-01'], freq='D')
214+
215+
with tm.assert_produces_warning(FutureWarning):
216+
idx.summary()

pandas/tests/indexes/test_base.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,14 +1055,21 @@ def test_is_all_dates(self):
10551055
assert not self.intIndex.is_all_dates
10561056

10571057
def test_summary(self):
1058-
self._check_method_works(Index.summary)
1058+
self._check_method_works(Index._summary)
10591059
# GH3869
10601060
ind = Index(['{other}%s', "~:{range}:0"], name='A')
1061-
result = ind.summary()
1061+
result = ind._summary()
10621062
# shouldn't be formatted accidentally.
10631063
assert '~:{range}:0' in result
10641064
assert '{other}%s' in result
10651065

1066+
# GH18217
1067+
def test_summary_deprecated(self):
1068+
ind = Index(['{other}%s', "~:{range}:0"], name='A')
1069+
1070+
with tm.assert_produces_warning(FutureWarning):
1071+
ind.summary()
1072+
10661073
def test_format(self):
10671074
self._check_method_works(Index.format)
10681075

pandas/tests/indexes/timedeltas/test_formats.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import pandas as pd
66
from pandas import TimedeltaIndex
77

8+
import pandas.util.testing as tm
9+
810

911
class TestTimedeltaIndexRendering(object):
1012
@pytest.mark.parametrize('method', ['__repr__', '__unicode__', '__str__'])
@@ -67,6 +69,11 @@ def test_representation_to_series(self):
6769
result = repr(pd.Series(idx))
6870
assert result == expected
6971

72+
def test_summary_deprecated(self):
73+
idx = TimedeltaIndex([], freq='D')
74+
with tm.assert_produces_warning(FutureWarning):
75+
idx.summary()
76+
7077
def test_summary(self):
7178
# GH#9116
7279
idx1 = TimedeltaIndex([], freq='D')
@@ -92,5 +99,5 @@ def test_summary(self):
9299

93100
for idx, expected in zip([idx1, idx2, idx3, idx4, idx5],
94101
[exp1, exp2, exp3, exp4, exp5]):
95-
result = idx.summary()
102+
result = idx._summary()
96103
assert result == expected

0 commit comments

Comments
 (0)