From 3a8df4902de2fa8d39753c83ca5cbcd19095351d Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Mon, 10 May 2021 21:32:03 -0500 Subject: [PATCH] CLN: fix numpy FutureWarning in tests --- pandas/tests/arithmetic/test_object.py | 2 +- pandas/tests/dtypes/test_inference.py | 2 +- pandas/tests/test_common.py | 3 +-- pandas/tests/tools/test_to_datetime.py | 8 ++++++-- pandas/tests/util/test_hashing.py | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pandas/tests/arithmetic/test_object.py b/pandas/tests/arithmetic/test_object.py index c5e086d24ec0c..1961a2d9d89f8 100644 --- a/pandas/tests/arithmetic/test_object.py +++ b/pandas/tests/arithmetic/test_object.py @@ -311,7 +311,7 @@ def test_sub_object(self): index - "foo" with pytest.raises(TypeError, match=msg): - index - np.array([2, "foo"]) + index - np.array([2, "foo"], dtype=object) def test_rsub_object(self): # GH#19369 diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index 076cc155f3626..d16dda370c498 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -1042,7 +1042,7 @@ def test_infer_dtype_datetime64_with_na(self, na_value): np.array([np.datetime64("2011-01-01"), Timestamp("2011-01-02")]), np.array([Timestamp("2011-01-02"), np.datetime64("2011-01-01")]), np.array([np.nan, Timestamp("2011-01-02"), 1.1]), - np.array([np.nan, "2011-01-01", Timestamp("2011-01-02")]), + np.array([np.nan, "2011-01-01", Timestamp("2011-01-02")], dtype=object), np.array([np.datetime64("nat"), np.timedelta64(1, "D")], dtype=object), np.array([np.timedelta64(1, "D"), np.datetime64("nat")], dtype=object), ], diff --git a/pandas/tests/test_common.py b/pandas/tests/test_common.py index 0b2a4cfb94d18..93c95b3004876 100644 --- a/pandas/tests/test_common.py +++ b/pandas/tests/test_common.py @@ -163,6 +163,5 @@ def test_serializable(obj): class TestIsBoolIndexer: def test_non_bool_array_with_na(self): # in particular, this should not raise - arr = np.array(["A", "B", np.nan]) - + arr = np.array(["A", "B", np.nan], dtype=object) assert not com.is_bool_indexer(arr) diff --git a/pandas/tests/tools/test_to_datetime.py b/pandas/tests/tools/test_to_datetime.py index 3e0c12c6a22cc..eb38f2f95d2d5 100644 --- a/pandas/tests/tools/test_to_datetime.py +++ b/pandas/tests/tools/test_to_datetime.py @@ -1899,7 +1899,10 @@ def test_to_datetime_infer_datetime_format_inconsistent_format(self, cache): @pytest.mark.parametrize("cache", [True, False]) def test_to_datetime_infer_datetime_format_series_with_nans(self, cache): s = Series( - np.array(["01/01/2011 00:00:00", np.nan, "01/03/2011 00:00:00", np.nan]) + np.array( + ["01/01/2011 00:00:00", np.nan, "01/03/2011 00:00:00", np.nan], + dtype=object, + ) ) tm.assert_series_equal( to_datetime(s, infer_datetime_format=False, cache=cache), @@ -1916,7 +1919,8 @@ def test_to_datetime_infer_datetime_format_series_start_with_nans(self, cache): "01/01/2011 00:00:00", "01/02/2011 00:00:00", "01/03/2011 00:00:00", - ] + ], + dtype=object, ) ) diff --git a/pandas/tests/util/test_hashing.py b/pandas/tests/util/test_hashing.py index e373323dfb6e1..8ce24dc963dc5 100644 --- a/pandas/tests/util/test_hashing.py +++ b/pandas/tests/util/test_hashing.py @@ -90,7 +90,7 @@ def test_hash_array(series): @pytest.mark.parametrize( - "arr2", [np.array([3, 4, "All"]), np.array([3, 4, "All"], dtype=object)] + "arr2", [np.array([3, 4, "All"], dtype="U"), np.array([3, 4, "All"], dtype=object)] ) def test_hash_array_mixed(arr2): result1 = hash_array(np.array(["3", "4", "All"]))