From 135c12deea8431624c932b5eb78d38628133a80e Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 1 Feb 2021 13:18:55 -0800 Subject: [PATCH 1/3] TST: update exception message, xfail --- pandas/tests/indexes/test_numeric.py | 9 ++++++++- pandas/tests/tseries/offsets/test_offsets_properties.py | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pandas/tests/indexes/test_numeric.py b/pandas/tests/indexes/test_numeric.py index e391b76ddbd15..1cf07dc05dbad 100644 --- a/pandas/tests/indexes/test_numeric.py +++ b/pandas/tests/indexes/test_numeric.py @@ -4,6 +4,7 @@ import pytest from pandas._libs.tslibs import Timestamp +from pandas.compat import np_version_under1p20 import pandas as pd from pandas import Float64Index, Index, Int64Index, RangeIndex, Series, UInt64Index @@ -204,12 +205,18 @@ 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" ) - with pytest.raises(TypeError, match=msg): + err = TypeError + if not np_version_under1p20: + err = ValueError + msg = "could not convert string to float: 'a'" + with pytest.raises(err, 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 From b8684d85f4b547189cc11da39b40562ea4cfa37c Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 1 Feb 2021 14:15:22 -0800 Subject: [PATCH 2/3] 32bit compat --- pandas/tests/indexes/test_numeric.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pandas/tests/indexes/test_numeric.py b/pandas/tests/indexes/test_numeric.py index 1cf07dc05dbad..d6b92999305b2 100644 --- a/pandas/tests/indexes/test_numeric.py +++ b/pandas/tests/indexes/test_numeric.py @@ -4,7 +4,6 @@ import pytest from pandas._libs.tslibs import Timestamp -from pandas.compat import np_version_under1p20 import pandas as pd from pandas import Float64Index, Index, Int64Index, RangeIndex, Series, UInt64Index @@ -206,15 +205,14 @@ 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'", + ] ) - err = TypeError - if not np_version_under1p20: - err = ValueError - msg = "could not convert string to float: 'a'" - with pytest.raises(err, 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'" From bff72a70f5af8feb3e1a1c7efebc4536276763d6 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 1 Feb 2021 14:30:04 -0800 Subject: [PATCH 3/3] avoid numpy deprecation warning --- pandas/core/indexes/multi.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 0d30c1665df34..46dbcdaab42b0 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1282,16 +1282,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: