Skip to content

TST: numpy RuntimeWarning with Series.round() #25432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import numpy as np
import pytest

from pandas.compat import PY35, lrange
from pandas.compat import PY2, PY35, lrange, is_platform_windows
import pandas.util._test_decorators as td

import pandas as pd
Expand Down Expand Up @@ -1842,6 +1842,16 @@ def test_numpy_round(self):
with pytest.raises(ValueError, match=msg):
np.round(df, decimals=0, out=df)

@pytest.mark.skipif(
PY2 and is_platform_windows(), reason="numpy/numpy#7882")
def test_numpy_round_nan(self):
# See gh-14197
df = Series([1.53, np.nan, 0.06]).to_frame()
with np.errstate(invalid='raise'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can u add assert_produces_warning() to these tests asserting that no warning happens

Copy link
Member Author

@simonjayhawkins simonjayhawkins Feb 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think there is any value add. the RuntimeWarning issued by numpy seems to be only issued once and therefore is highly unlikely to be detected by a test unless run in isolation. hence the with np.errstate(invalid='raise'): context mangaer is used to convert the RuntimeWarning: invalid value encountered in rint to FloatingPointError: invalid value encountered in rint. Also assert_produces_warning is not thread-safe.

issues warning for both tests in py2 windows pytest environment. (i was not able to run pytest in my py2 environment.)

np.errstate now replaced with assert_produces_warning.

result = df.round()
expected = Series([2., np.nan, 0.]).to_frame()
tm.assert_frame_equal(result, expected)

def test_round_mixed_type(self):
# GH 11885
df = DataFrame({'col1': [1.1, 2.2, 3.3, 4.4],
Expand Down
12 changes: 11 additions & 1 deletion pandas/tests/series/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from numpy import nan
import pytest

from pandas.compat import PY35, lrange, range
from pandas.compat import PY2, PY35, is_platform_windows, lrange, range
import pandas.util._test_decorators as td

import pandas as pd
Expand Down Expand Up @@ -285,6 +285,16 @@ def test_numpy_round(self):
with pytest.raises(ValueError, match=msg):
np.round(s, decimals=0, out=s)

@pytest.mark.skipif(
PY2 and is_platform_windows(), reason="numpy/numpy#7882")
def test_numpy_round_nan(self):
# See gh-14197
s = Series([1.53, np.nan, 0.06])
with np.errstate(invalid='raise'):
result = s.round()
expected = Series([2., np.nan, 0.])
assert_series_equal(result, expected)

def test_built_in_round(self):
if not compat.PY3:
pytest.skip(
Expand Down