Skip to content

Commit 951f055

Browse files
committed
Merge pull request #6986 from jreback/warnings2
COMPAT: remove deprecated optinos from printing in test suite (GH6984)
2 parents be29fd2 + d6f9b79 commit 951f055

File tree

7 files changed

+40
-26
lines changed

7 files changed

+40
-26
lines changed

doc/source/release.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ Deprecations
198198
will not be supported in a future release (:issue:`6645`)
199199

200200
- Indexers will warn ``FutureWarning`` when used with a scalar indexer and
201-
a non-floating point Index (:issue:`4892`)
201+
a non-floating point Index (:issue:`4892`, :issue:`6960`)
202+
203+
- Numpy 1.9 compat w.r.t. deprecation warnings (:issue:`6960`)
202204

203205
- :meth:`Panel.shift` now has a function signature that matches :meth:`DataFrame.shift`.
204206
The old positional argument ``lags`` has been changed to a keyword argument

doc/source/v0.14.0.txt

+17-9
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ Deprecations
392392
will not be supported in a future release (:issue:`6645`)
393393

394394
- Indexers will warn ``FutureWarning`` when used with a scalar indexer and
395-
a non-floating point Index (:issue:`4892`)
395+
a non-floating point Index (:issue:`4892`, :issue:`6960`)
396396

397397
.. code-block:: python
398398

@@ -401,17 +401,25 @@ Deprecations
401401
pandas/core/index.py:469: FutureWarning: scalar indexers for index type Int64Index should be integers and not floating point
402402
Out[1]: 1
403403

404-
In [5]: Series(1,np.arange(5)).iloc[3.0]
404+
In [2]: Series(1,np.arange(5)).iloc[3.0]
405405
pandas/core/index.py:469: FutureWarning: scalar indexers for index type Int64Index should be integers and not floating point
406-
Out[5]: 1
406+
Out[2]: 1
407407

408-
# these are Float64Indexes, so integer or floating point is acceptable
409-
In [3]: Series(1,np.arange(5.))[3]
410-
Out[3]: 1
408+
In [3]: Series(1,np.arange(5)).iloc[3.0:4]
409+
pandas/core/index.py:527: FutureWarning: slice indexers when using iloc should be integers and not floating point
410+
Out[3]:
411+
3 1
412+
dtype: int64
411413

412-
In [4]: Series(1,np.arange(5.))[3.0]
414+
# these are Float64Indexes, so integer or floating point is acceptable
415+
In [4]: Series(1,np.arange(5.))[3]
413416
Out[4]: 1
414417

418+
In [5]: Series(1,np.arange(5.))[3.0]
419+
Out[6]: 1
420+
421+
- Numpy 1.9 compat w.r.t. deprecation warnings (:issue:`6960`)
422+
415423
- :meth:`Panel.shift` now has a function signature that matches :meth:`DataFrame.shift`.
416424
The old positional argument ``lags`` has been changed to a keyword argument
417425
``periods`` with a default value of 1. A ``FutureWarning`` is raised if the
@@ -484,13 +492,13 @@ Enhancements
484492
- Added ``how`` option to rolling-moment functions to dictate how to handle resampling; :func:``rolling_max`` defaults to max,
485493
:func:``rolling_min`` defaults to min, and all others default to mean (:issue:`6297`)
486494
- ``CustomBuisnessMonthBegin`` and ``CustomBusinessMonthEnd`` are now available (:issue:`6866`)
487-
- :meth:`Series.quantile` and :meth:`DataFrame.quantile` now accept an array of
495+
- :meth:`Series.quantile` and :meth:`DataFrame.quantile` now accept an array of
488496
quantiles.
489497
- ``pivot_table`` can now accept ``Grouper`` by ``index`` and ``columns`` keywords (:issue:`6913`)
490498

491499
.. ipython:: python
492500

493-
import datetime
501+
import datetime
494502
df = DataFrame({
495503
'Branch' : 'A A A A A B'.split(),
496504
'Buyer': 'Carl Mark Carl Carl Joe Joe'.split(),

pandas/core/config.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _describe_option(pat='', _print_desc=True):
140140
return s
141141

142142

143-
def _reset_option(pat):
143+
def _reset_option(pat, silent=False):
144144

145145
keys = _select_options(pat)
146146

@@ -154,7 +154,7 @@ def _reset_option(pat):
154154
'value')
155155

156156
for k in keys:
157-
_set_option(k, _registered_options[k].defval)
157+
_set_option(k, _registered_options[k].defval, silent=silent)
158158

159159

160160
def get_default_val(pat):
@@ -361,7 +361,7 @@ def __enter__(self):
361361
def __exit__(self, *args):
362362
if self.undo:
363363
for pat, val in self.undo:
364-
_set_option(pat, val)
364+
_set_option(pat, val, silent=True)
365365

366366

367367
def register_option(key, defval, doc='', validator=None, cb=None):
@@ -567,6 +567,7 @@ def _warn_if_deprecated(key):
567567
d = _get_deprecated_option(key)
568568
if d:
569569
if d.msg:
570+
print(d.msg)
570571
warnings.warn(d.msg, DeprecationWarning)
571572
else:
572573
msg = "'%s' is deprecated" % key

pandas/tests/test_format.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ def test_eng_float_formatter(self):
104104

105105
fmt.set_eng_float_format(accuracy=0)
106106
repr(self.frame)
107-
108-
fmt.reset_option('^display.')
107+
self.reset_display_options()
109108

110109
def test_repr_tuples(self):
111110
buf = StringIO()
@@ -1034,7 +1033,7 @@ def test_to_string_no_index(self):
10341033
assert(df_s == expected)
10351034

10361035
def test_to_string_float_formatting(self):
1037-
fmt.reset_option('^display.')
1036+
self.reset_display_options()
10381037
fmt.set_option('display.precision', 6, 'display.column_space',
10391038
12, 'display.notebook_repr_html', False)
10401039

@@ -1065,7 +1064,7 @@ def test_to_string_float_formatting(self):
10651064
'1 0.253')
10661065
assert(df_s == expected)
10671066

1068-
fmt.reset_option('^display.')
1067+
self.reset_display_options()
10691068
self.assertEqual(get_option("display.precision"), 7)
10701069

10711070
df = DataFrame({'x': [1e9, 0.2512]})
@@ -1157,7 +1156,7 @@ def test_to_string_index_formatter(self):
11571156
self.assertEqual(rs, xp)
11581157

11591158
def test_to_string_left_justify_cols(self):
1160-
fmt.reset_option('^display.')
1159+
self.reset_display_options()
11611160
df = DataFrame({'x': [3234, 0.253]})
11621161
df_s = df.to_string(justify='left')
11631162
expected = (' x \n'
@@ -1166,7 +1165,7 @@ def test_to_string_left_justify_cols(self):
11661165
assert(df_s == expected)
11671166

11681167
def test_to_string_format_na(self):
1169-
fmt.reset_option('^display.')
1168+
self.reset_display_options()
11701169
df = DataFrame({'A': [np.nan, -1, -2.1234, 3, 4],
11711170
'B': [np.nan, 'foo', 'foooo', 'fooooo', 'bar']})
11721171
result = df.to_string()
@@ -1434,14 +1433,14 @@ def test_repr_html(self):
14341433
fmt.set_option('display.notebook_repr_html', False)
14351434
self.frame._repr_html_()
14361435

1437-
fmt.reset_option('^display.')
1436+
self.reset_display_options()
14381437

14391438
df = DataFrame([[1, 2], [3, 4]])
14401439
self.assertTrue('2 rows' in df._repr_html_())
14411440
fmt.set_option('display.show_dimensions', False)
14421441
self.assertFalse('2 rows' in df._repr_html_())
14431442

1444-
fmt.reset_option('^display.')
1443+
self.reset_display_options()
14451444

14461445
def test_repr_html_wide(self):
14471446
row = lambda l, k: [tm.rands(k) for _ in range(l)]
@@ -1580,7 +1579,7 @@ def get_ipython():
15801579
repstr = self.frame._repr_html_()
15811580
self.assertIn('class', repstr) # info fallback
15821581

1583-
fmt.reset_option('^display.')
1582+
self.reset_display_options()
15841583

15851584
def test_to_html_with_classes(self):
15861585
df = pandas.DataFrame()
@@ -2092,7 +2091,7 @@ def test_eng_float_formatter(self):
20922091
'3 1E+06')
20932092
self.assertEqual(result, expected)
20942093

2095-
fmt.reset_option('^display.')
2094+
self.reset_display_options()
20962095

20972096
def compare(self, formatter, input, output):
20982097
formatted_input = formatter(input)

pandas/tests/test_frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4355,7 +4355,7 @@ def test_repr_dimensions(self):
43554355
fmt.set_option('display.show_dimensions', False)
43564356
self.assertFalse("2 rows x 2 columns" in repr(df))
43574357

4358-
fmt.reset_option('^display\.')
4358+
self.reset_display_options()
43594359

43604360
@slow
43614361
def test_repr_big(self):
@@ -4391,7 +4391,7 @@ def test_repr_unsortable(self):
43914391
fmt.set_option('display.max_rows', 1000, 'display.max_columns', 1000)
43924392
repr(self.frame)
43934393

4394-
fmt.reset_option('^display\.')
4394+
self.reset_display_options()
43954395

43964396
warnings.filters = warn_filters
43974397

pandas/tests/test_index.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,7 @@ def test_format_sparse_config(self):
21452145
result = self.index.format()
21462146
self.assertEqual(result[1], 'foo two')
21472147

2148-
pd.reset_option("^display\.")
2148+
self.reset_display_options()
21492149

21502150
warnings.filters = warn_filters
21512151

pandas/util/testing.py

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ def setUpClass(cls):
6969
def tearDownClass(cls):
7070
pass
7171

72+
def reset_display_options(self):
73+
# reset the display options
74+
pd.reset_option('^display.',silent=True)
75+
7276
def assert_numpy_array_equal(self, np_array, assert_equal):
7377
if np.array_equal(np_array, assert_equal):
7478
return

0 commit comments

Comments
 (0)