Skip to content

Commit ca28f25

Browse files
committed
Adjust some tests
1 parent 87aa7ac commit ca28f25

File tree

4 files changed

+8
-43
lines changed

4 files changed

+8
-43
lines changed

pandas/tests/dtypes/test_inference.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
missing as libmissing,
3535
ops as libops,
3636
)
37-
from pandas.compat.numpy import np_version_gt2
3837

3938
from pandas.core.dtypes import inference
4039
from pandas.core.dtypes.cast import find_result_type
@@ -1989,7 +1988,7 @@ def test_ensure_int32():
19891988
# find a smaller floating dtype
19901989
(300.0, np.uint16), # for integer floats, we convert them to ints
19911990
(300.1, np.float64),
1992-
(np.int16(300), np.int16 if np_version_gt2 else np.uint16),
1991+
(np.int16(300), np.uint16),
19931992
],
19941993
)
19951994
def test_find_result_type_uint_int(right, result):

pandas/tests/indexing/test_coercion.py

-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
IS64,
1616
is_platform_windows,
1717
)
18-
from pandas.compat.numpy import np_version_gt2
1918

2019
import pandas as pd
2120
import pandas._testing as tm
@@ -219,8 +218,6 @@ def test_insert_int_index(
219218
"insert, coerced_val, coerced_dtype",
220219
[
221220
(1, 1.0, None),
222-
# When float_numpy_dtype=float32, this is not the case
223-
# see the correction below
224221
(1.1, 1.1, np.float64),
225222
(False, False, object), # GH#36319
226223
("x", "x", object),
@@ -232,11 +229,6 @@ def test_insert_float_index(
232229
dtype = float_numpy_dtype
233230
obj = pd.Index([1.0, 2.0, 3.0, 4.0], dtype=dtype)
234231
coerced_dtype = coerced_dtype if coerced_dtype is not None else dtype
235-
236-
if np_version_gt2 and dtype == "float32" and coerced_val == 1.1:
237-
# Hack, in the 2nd test case, since 1.1 can be losslessly cast to float32
238-
# the expected dtype will be float32 if the original dtype was float32
239-
coerced_dtype = np.float32
240232
exp = pd.Index([1.0, coerced_val, 2.0, 3.0, 4.0], dtype=coerced_dtype)
241233
self._assert_insert_conversion(obj, insert, exp, coerced_dtype)
242234

pandas/tests/indexing/test_loc.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from pandas._config import using_pyarrow_string_dtype
1717

1818
from pandas._libs import index as libindex
19-
from pandas.compat.numpy import np_version_gt2
2019
from pandas.errors import IndexingError
2120

2221
import pandas as pd
@@ -2976,16 +2975,7 @@ def test_loc_setitem_uint8_upcast(value):
29762975
df = DataFrame([1, 2, 3, 4], columns=["col1"], dtype="uint8")
29772976
with tm.assert_produces_warning(FutureWarning, match="item of incompatible dtype"):
29782977
df.loc[2, "col1"] = value # value that can't be held in uint8
2979-
2980-
if np_version_gt2 and isinstance(value, np.int16):
2981-
# Note, result type of uint8 + int16 is int16
2982-
# in numpy < 2, though, numpy would inspect the
2983-
# value and see that it could fit in an uint16, resulting in a uint16
2984-
dtype = "int16"
2985-
else:
2986-
dtype = "uint16"
2987-
2988-
expected = DataFrame([1, 2, 300, 4], columns=["col1"], dtype=dtype)
2978+
expected = DataFrame([1, 2, 300, 4], columns=["col1"], dtype="uint16")
29892979
tm.assert_frame_equal(df, expected)
29902980

29912981

pandas/tests/series/test_constructors.py

+6-22
Original file line numberDiff line numberDiff line change
@@ -769,12 +769,8 @@ def test_constructor_cast(self):
769769

770770
def test_constructor_signed_int_overflow_raises(self):
771771
# GH#41734 disallow silent overflow, enforced in 2.0
772-
if np_version_gt2:
773-
msg = "The elements provided in the data cannot all be casted to the dtype"
774-
err = OverflowError
775-
else:
776-
msg = "Values are too large to be losslessly converted"
777-
err = ValueError
772+
msg = "Values are too large to be losslessly converted"
773+
err = ValueError
778774
with pytest.raises(err, match=msg):
779775
Series([1, 200, 923442], dtype="int8")
780776

@@ -802,13 +798,7 @@ def test_constructor_numpy_uints(self, values):
802798

803799
def test_constructor_unsigned_dtype_overflow(self, any_unsigned_int_numpy_dtype):
804800
# see gh-15832
805-
if np_version_gt2:
806-
msg = (
807-
f"The elements provided in the data cannot "
808-
f"all be casted to the dtype {any_unsigned_int_numpy_dtype}"
809-
)
810-
else:
811-
msg = "Trying to coerce negative values to unsigned integers"
801+
msg = "Trying to coerce negative values to unsigned integers"
812802
with pytest.raises(OverflowError, match=msg):
813803
Series([-1], dtype=any_unsigned_int_numpy_dtype)
814804

@@ -1938,15 +1928,9 @@ def test_constructor_int64_dtype(self, any_int_dtype):
19381928

19391929
def test_constructor_raise_on_lossy_conversion_of_strings(self):
19401930
# GH#44923
1941-
if not np_version_gt2:
1942-
raises = pytest.raises(
1943-
ValueError, match="string values cannot be losslessly cast to int8"
1944-
)
1945-
else:
1946-
raises = pytest.raises(
1947-
OverflowError, match="The elements provided in the data"
1948-
)
1949-
with raises:
1931+
with pytest.raises(
1932+
ValueError, match="string values cannot be losslessly cast to int8"
1933+
):
19501934
Series(["128"], dtype="int8")
19511935

19521936
def test_constructor_dtype_timedelta_alternative_construct(self):

0 commit comments

Comments
 (0)