diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index a9d93f473e0e1..2ef9e4a028793 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -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: diff --git a/pandas/tests/indexes/test_numeric.py b/pandas/tests/indexes/test_numeric.py index ff1632e33c0fb..d12e9465949b4 100644 --- a/pandas/tests/indexes/test_numeric.py +++ b/pandas/tests/indexes/test_numeric.py @@ -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")]) diff --git a/pandas/tests/tseries/offsets/test_offsets_properties.py b/pandas/tests/tseries/offsets/test_offsets_properties.py index 8d9b54cf3f0df..edb0f8c7dd662 100644 --- a/pandas/tests/tseries/offsets/test_offsets_properties.py +++ b/pandas/tests/tseries/offsets/test_offsets_properties.py @@ -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 @@ -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