Skip to content

Commit

Permalink
Backport PR pandas-dev#39546: CI/TST: update exception message, xfail
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored and meeseeksmachine committed Feb 1, 2021
1 parent ddb051b commit c4ca7d4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
10 changes: 6 additions & 4 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1286,16 +1286,18 @@ def _format_native_types(self, na_rep="nan", **kwargs):

# go through the levels and format them
for level, level_codes in zip(self.levels, self.codes):
level = level._format_native_types(na_rep=na_rep, **kwargs)
level_strs = level._format_native_types(na_rep=na_rep, **kwargs)
# add nan values, if there are any
mask = level_codes == -1
if mask.any():
nan_index = len(level)
level = np.append(level, na_rep)
nan_index = len(level_strs)
# numpy 1.21 deprecated implicit string casting
level_strs = level_strs.astype(str)
level_strs = np.append(level_strs, na_rep)
assert not level_codes.flags.writeable # i.e. copy is needed
level_codes = level_codes.copy() # make writeable
level_codes[mask] = nan_index
new_levels.append(level)
new_levels.append(level_strs)
new_codes.append(level_codes)

if len(new_levels) == 1:
Expand Down
13 changes: 9 additions & 4 deletions pandas/tests/indexes/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,17 @@ def test_constructor_invalid(self):
)
with pytest.raises(TypeError, match=msg):
Float64Index(0.0)
msg = (
"String dtype not supported, "
"you may need to explicitly cast to a numeric type"

# 2021-02-1 we get ValueError in numpy 1.20, but not on all builds
msg = "|".join(
[
"String dtype not supported, you may need to explicitly cast ",
"could not convert string to float: 'a'",
]
)
with pytest.raises(TypeError, match=msg):
with pytest.raises((TypeError, ValueError), match=msg):
Float64Index(["a", "b", 0.0])

msg = r"float\(\) argument must be a string or a number, not 'Timestamp'"
with pytest.raises(TypeError, match=msg):
Float64Index([Timestamp("20130101")])
Expand Down
2 changes: 2 additions & 0 deletions pandas/tests/tseries/offsets/test_offsets_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import warnings

from hypothesis import assume, given, strategies as st
from hypothesis.errors import Flaky
from hypothesis.extra.dateutil import timezones as dateutil_timezones
from hypothesis.extra.pytz import timezones as pytz_timezones
import pytest
Expand Down Expand Up @@ -103,6 +104,7 @@ def test_on_offset_implementations(dt, offset):
assert offset.is_on_offset(dt) == (compare == dt)


@pytest.mark.xfail(strict=False, raises=Flaky, reason="unreliable test timings")
@given(gen_yqm_offset)
def test_shift_across_dst(offset):
# GH#18319 check that 1) timezone is correctly normalized and
Expand Down

0 comments on commit c4ca7d4

Please sign in to comment.