Skip to content

Commit bd70e75

Browse files
GGordonGordonjreback
authored andcommitted
CLN: Deprecate Index.summary (GH18217) (#20028)
1 parent 4eb9769 commit bd70e75

File tree

8 files changed

+56
-17
lines changed

8 files changed

+56
-17
lines changed

doc/source/whatsnew/v0.23.0.txt

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

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

742743
.. _whatsnew_0230.prior_deprecations:
743744

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
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__)

pandas/core/indexes/base.py

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

1387-
def summary(self, name=None):
1387+
def _summary(self, name=None):
1388+
"""
1389+
Return a summarized representation
1390+
1391+
Parameters
1392+
----------
1393+
name : str
1394+
name to use in the summary representation
1395+
1396+
Returns
1397+
-------
1398+
String with a summarized representation of the index
1399+
"""
13881400
if len(self) > 0:
13891401
head = self[0]
13901402
if (hasattr(head, 'format') and
@@ -1403,6 +1415,15 @@ def summary(self, name=None):
14031415
name = type(self).__name__
14041416
return '%s: %s entries%s' % (name, len(self), index_summary)
14051417

1418+
def summary(self, name=None):
1419+
"""
1420+
Return a summarized representation
1421+
.. deprecated:: 0.23.0
1422+
"""
1423+
warnings.warn("'summary' is deprecated and will be removed in a "
1424+
"future version.", FutureWarning, stacklevel=2)
1425+
return self._summary(name)
1426+
14061427
def _mpl_repr(self):
14071428
# how to represent ourselves to matplotlib
14081429
return self.values

pandas/core/indexes/datetimelike.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,9 +1049,18 @@ 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
"""
1054-
return a summarized representation
1054+
Return a summarized representation
1055+
1056+
Parameters
1057+
----------
1058+
name : str
1059+
name to use in the summary representation
1060+
1061+
Returns
1062+
-------
1063+
String with a summarized representation of the index
10551064
"""
10561065
formatter = self._formatter_func
10571066
if len(self) > 0:

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,5 @@ 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

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@ def test_summary(self):
9292

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

0 commit comments

Comments
 (0)