Skip to content

Commit faf4012

Browse files
Backport PR #39546: CI/TST: update exception message, xfail (#39549)
Co-authored-by: jbrockmendel <[email protected]>
1 parent ddb051b commit faf4012

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

pandas/core/indexes/multi.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1286,16 +1286,18 @@ def _format_native_types(self, na_rep="nan", **kwargs):
12861286

12871287
# go through the levels and format them
12881288
for level, level_codes in zip(self.levels, self.codes):
1289-
level = level._format_native_types(na_rep=na_rep, **kwargs)
1289+
level_strs = level._format_native_types(na_rep=na_rep, **kwargs)
12901290
# add nan values, if there are any
12911291
mask = level_codes == -1
12921292
if mask.any():
1293-
nan_index = len(level)
1294-
level = np.append(level, na_rep)
1293+
nan_index = len(level_strs)
1294+
# numpy 1.21 deprecated implicit string casting
1295+
level_strs = level_strs.astype(str)
1296+
level_strs = np.append(level_strs, na_rep)
12951297
assert not level_codes.flags.writeable # i.e. copy is needed
12961298
level_codes = level_codes.copy() # make writeable
12971299
level_codes[mask] = nan_index
1298-
new_levels.append(level)
1300+
new_levels.append(level_strs)
12991301
new_codes.append(level_codes)
13001302

13011303
if len(new_levels) == 1:

pandas/tests/indexes/test_numeric.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,17 @@ def test_constructor_invalid(self):
204204
)
205205
with pytest.raises(TypeError, match=msg):
206206
Float64Index(0.0)
207-
msg = (
208-
"String dtype not supported, "
209-
"you may need to explicitly cast to a numeric type"
207+
208+
# 2021-02-1 we get ValueError in numpy 1.20, but not on all builds
209+
msg = "|".join(
210+
[
211+
"String dtype not supported, you may need to explicitly cast ",
212+
"could not convert string to float: 'a'",
213+
]
210214
)
211-
with pytest.raises(TypeError, match=msg):
215+
with pytest.raises((TypeError, ValueError), match=msg):
212216
Float64Index(["a", "b", 0.0])
217+
213218
msg = r"float\(\) argument must be a string or a number, not 'Timestamp'"
214219
with pytest.raises(TypeError, match=msg):
215220
Float64Index([Timestamp("20130101")])

pandas/tests/tseries/offsets/test_offsets_properties.py

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import warnings
1111

1212
from hypothesis import assume, given, strategies as st
13+
from hypothesis.errors import Flaky
1314
from hypothesis.extra.dateutil import timezones as dateutil_timezones
1415
from hypothesis.extra.pytz import timezones as pytz_timezones
1516
import pytest
@@ -103,6 +104,7 @@ def test_on_offset_implementations(dt, offset):
103104
assert offset.is_on_offset(dt) == (compare == dt)
104105

105106

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

0 commit comments

Comments
 (0)