Skip to content

TST: avoid/suppress DeprecationWarnings #37570

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 2 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions pandas/core/arrays/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,11 @@ def _arith_method(self, other, op):
dtype = "bool"
result = np.zeros(len(self._data), dtype=dtype)
else:
if op_name in {"pow", "rpow"} and isinstance(other, np.bool_):
# Avoid DeprecationWarning: In future, it will be an error
# for 'np.bool_' scalars to be interpreted as an index
other = bool(other)

with np.errstate(all="ignore"):
result = op(self._data, other)

Expand Down
13 changes: 11 additions & 2 deletions pandas/tests/indexes/test_index_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,25 @@ def test_constructor_infer_nat_dt_like(
data = [ctor]
data.insert(pos, nulls_fixture)

warn = None
if nulls_fixture is NA:
expected = Index([NA, NaT])
mark = pytest.mark.xfail(reason="Broken with np.NaT ctor; see GH 31884")
request.node.add_marker(mark)
# GH#35942 numpy will emit a DeprecationWarning within the
# assert_index_equal calls. Since we can't do anything
# about it until GH#31884 is fixed, we suppress that warning.
warn = DeprecationWarning

result = Index(data)
tm.assert_index_equal(result, expected)

with tm.assert_produces_warning(warn):
tm.assert_index_equal(result, expected)

result = Index(np.array(data, dtype=object))
tm.assert_index_equal(result, expected)

with tm.assert_produces_warning(warn):
tm.assert_index_equal(result, expected)

@pytest.mark.parametrize("swap_objs", [True, False])
def test_constructor_mixed_nat_objs_infers_object(self, swap_objs):
Expand Down