@@ -5527,48 +5527,48 @@ def test_same_value_cast_floats_precision_loss(self, dtype):
55275527 with pytest .raises (ValueError ):
55285528 q .astype (dtype , casting = "same_value" )
55295529
5530- # @pytest.mark.parametrize("dtype", [
5531- # "S50", "U50", "<U50", "S100", "U100", np.dtypes.StringDType()
5532- # ])
5533- # def test_same_value_cast_strings_enough_width(self, dtype):
5534- # """Test that string types with enough width can represent quad values exactly."""
5535- # values = [
5536- # "0.0", "-0.0", "1.0", "-1.0",
5537- # "3.14159265358979323846264338327950288", # pi with full quad precision
5538- # "inf", "-inf", "nan",
5539- # "1.23e100", "-4.56e-100",
5540- # ]
5541-
5542- # for val in values:
5543- # q = np.array([val], dtype=QuadPrecDType())
5544- # result = q.astype(dtype, casting="same_value")
5545- # # Convert back and verify
5546- # back = result.astype(QuadPrecDType())
5547- # if np.isnan(q[0]):
5548- # assert np.isnan(back[0]), f"NaN roundtrip failed for {dtype}"
5549- # else:
5550- # assert q[0] == back[0], f"Value {val} roundtrip failed for {dtype}"
5551-
5552- # @pytest.mark.parametrize("dtype", ["S10", "U10", "<U10"])
5553- # def test_same_value_cast_strings_narrow_width(self, dtype):
5554- # """Test that string types with narrow width fail for values that need more precision."""
5555- # # Values that can fit in 10 chars should pass
5556- # passing_values = ["0.0", "1.0", "-1.0", "inf", "-inf", "nan"]
5557- # for val in passing_values:
5558- # q = np.array([val], dtype=QuadPrecDType())
5559- # result = q.astype(dtype, casting="same_value")
5560- # back = result.astype(QuadPrecDType())
5561- # if np.isnan(q[0]):
5562- # assert np.isnan(back[0])
5563- # else:
5564- # assert q[0] == back[0], f"Value {val} should roundtrip in {dtype}"
5565-
5566- # # Values that need more than 10 chars should fail
5567- # failing_values = [
5568- # "3.14159265358979323846264338327950288", # pi
5569- # "1.23456789012345", # needs > 10 chars
5570- # ]
5571- # for val in failing_values:
5572- # q = np.array([val], dtype=QuadPrecDType())
5573- # with pytest.raises(ValueError):
5574- # q.astype(dtype, casting="same_value")
5530+ @pytest .mark .parametrize ("dtype" , [
5531+ "S50" , "U50" , "<U50" , "S100" , "U100" , np .dtypes .StringDType ()
5532+ ])
5533+ def test_same_value_cast_strings_enough_width (self , dtype ):
5534+ """Test that string types with enough width can represent quad values exactly."""
5535+ values = [
5536+ "0.0" , "-0.0" , "1.0" , "-1.0" ,
5537+ "3.14159265358979323846264338327950288" , # pi with full quad precision
5538+ "inf" , "-inf" , "nan" ,
5539+ "1.23e100" , "-4.56e-100" ,
5540+ ]
5541+
5542+ for val in values :
5543+ q = np .array ([val ], dtype = QuadPrecDType ())
5544+ result = q .astype (dtype , casting = "same_value" )
5545+ # Convert back and verify
5546+ back = result .astype (QuadPrecDType ())
5547+ if np .isnan (q [0 ]):
5548+ assert np .isnan (back [0 ]), f"NaN roundtrip failed for { dtype } "
5549+ else :
5550+ assert q [0 ] == back [0 ], f"Value { val } roundtrip failed for { dtype } "
5551+
5552+ @pytest .mark .parametrize ("dtype" , ["S10" , "U10" , "<U10" ])
5553+ def test_same_value_cast_strings_narrow_width (self , dtype ):
5554+ """Test that string types with narrow width fail for values that need more precision."""
5555+ # Values that can fit in 10 chars should pass
5556+ passing_values = ["0.0" , "1.0" , "-1.0" , "inf" , "-inf" , "nan" ]
5557+ for val in passing_values :
5558+ q = np .array ([val ], dtype = QuadPrecDType ())
5559+ result = q .astype (dtype , casting = "same_value" )
5560+ back = result .astype (QuadPrecDType ())
5561+ if np .isnan (q [0 ]):
5562+ assert np .isnan (back [0 ])
5563+ else :
5564+ assert q [0 ] == back [0 ], f"Value { val } should roundtrip in { dtype } "
5565+
5566+ # Values that need more than 10 chars should fail
5567+ failing_values = [
5568+ "3.14159265358979323846264338327950288" , # pi
5569+ "1.23456789012345" , # needs > 10 chars
5570+ ]
5571+ for val in failing_values :
5572+ q = np .array ([val ], dtype = QuadPrecDType ())
5573+ with pytest .raises (ValueError ):
5574+ q .astype (dtype , casting = "same_value" )
0 commit comments