Skip to content

Commit 5a2d31b

Browse files
committed
CLN: Deprecate Index.summary (GH18217)
1 parent 607910b commit 5a2d31b

File tree

8 files changed

+61
-19
lines changed

8 files changed

+61
-19
lines changed

doc/source/whatsnew/v0.23.0.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,8 @@ Deprecations
731731
- The ``order`` parameter of :func:`factorize` is deprecated and will be removed in a future release (:issue:`19727`)
732732
- :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`)
733733

734+
- ``Index.summary()`` is deprecated and will be removed in a future version (:issue:`18217`)
735+
734736
.. _whatsnew_0230.prior_deprecations:
735737

736738
Removal of prior version deprecations/changes

pandas/core/frame.py

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

18511851
lines.append(str(type(self)))
1852-
lines.append(self.index.summary())
1852+
lines.append(self.index._summary())
18531853

18541854
if len(self.columns) == 0:
18551855
lines.append('Empty %s' % type(self).__name__)
@@ -2185,7 +2185,7 @@ def __getitem__(self, key):
21852185
try:
21862186
if key in self.columns and not is_mi_columns:
21872187
return self._getitem_column(key)
2188-
except:
2188+
except Exception:
21892189
pass
21902190

21912191
# see if we can slice the rows
@@ -2638,7 +2638,7 @@ def _ensure_valid_index(self, value):
26382638
if not len(self.index) and is_list_like(value):
26392639
try:
26402640
value = Series(value)
2641-
except:
2641+
except Exception:
26422642
raise ValueError('Cannot set a frame with no defined index '
26432643
'and a value that cannot be converted to a '
26442644
'Series')
@@ -6226,7 +6226,7 @@ def convert(v):
62266226
values = np.array([convert(v) for v in values])
62276227
else:
62286228
values = convert(values)
6229-
except:
6229+
except Exception:
62306230
values = convert(values)
62316231

62326232
else:

pandas/core/indexes/base.py

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

1303-
def summary(self, name=None):
1303+
def _summary(self, name=None):
13041304
if len(self) > 0:
13051305
head = self[0]
13061306
if (hasattr(head, 'format') and
@@ -1319,6 +1319,15 @@ def summary(self, name=None):
13191319
name = type(self).__name__
13201320
return '%s: %s entries%s' % (name, len(self), index_summary)
13211321

1322+
def summary(self, name=None):
1323+
"""
1324+
.. deprecated:: 0.23.0
1325+
No longer supported
1326+
"""
1327+
warnings.warn("'summary' is deprecated and will be removed in a "
1328+
"future version.", FutureWarning, stacklevel=2)
1329+
return self._summary(name)
1330+
13221331
def _mpl_repr(self):
13231332
# how to represent ourselves to matplotlib
13241333
return self.values

pandas/core/indexes/datetimelike.py

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

944-
def summary(self, name=None):
944+
def _summary(self, name=None):
945945
"""
946946
return a summarized representation
947947
"""
@@ -963,6 +963,15 @@ def summary(self, name=None):
963963
result = result.replace("'", "")
964964
return result
965965

966+
def summary(self, name=None):
967+
"""
968+
.. deprecated:: 0.23.0
969+
No longer supported
970+
"""
971+
warnings.warn("'summary' is deprecated and will be removed in a "
972+
"future version.", FutureWarning, stacklevel=2)
973+
return self._summary(name)
974+
966975
def _concat_same_dtype(self, to_concat, name):
967976
"""
968977
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
@@ -1056,14 +1056,21 @@ def test_is_all_dates(self):
10561056
assert not self.intIndex.is_all_dates
10571057

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

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

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)