@@ -754,23 +754,67 @@ def test_constructor_unsigned_dtype_overflow(self, any_unsigned_int_numpy_dtype)
754
754
with pytest .raises (OverflowError , match = msg ):
755
755
Series ([- 1 ], dtype = any_unsigned_int_numpy_dtype )
756
756
757
+ @td .skip_if_no ("dask" )
758
+ def test_construct_dask_float_array_int_dtype_match_ndarray (self ):
759
+ # GH#40110 make sure we treat a float-dtype dask array with the same
760
+ # rules we would for an ndarray
761
+ import dask .dataframe as dd
762
+
763
+ arr = np .array ([1 , 2.5 , 3 ])
764
+ darr = dd .from_array (arr )
765
+
766
+ res = Series (darr )
767
+ expected = Series (arr )
768
+ tm .assert_series_equal (res , expected )
769
+
770
+ res = Series (darr , dtype = "i8" )
771
+ expected = Series (arr , dtype = "i8" )
772
+ tm .assert_series_equal (res , expected )
773
+
774
+ msg = "In a future version, passing float-dtype values containing NaN"
775
+ arr [2 ] = np .nan
776
+ with tm .assert_produces_warning (FutureWarning , match = msg ):
777
+ res = Series (darr , dtype = "i8" )
778
+ with tm .assert_produces_warning (FutureWarning , match = msg ):
779
+ expected = Series (arr , dtype = "i8" )
780
+ tm .assert_series_equal (res , expected )
781
+
757
782
def test_constructor_coerce_float_fail (self , any_int_numpy_dtype ):
758
783
# see gh-15832
759
- msg = "Trying to coerce float values to integers"
760
- with pytest .raises (ValueError , match = msg ):
761
- Series ([1 , 2 , 3.5 ], dtype = any_int_numpy_dtype )
784
+ # Updated: make sure we treat this list the same as we would treat
785
+ # the equivalent ndarray
786
+ vals = [1 , 2 , 3.5 ]
787
+
788
+ res = Series (vals , dtype = any_int_numpy_dtype )
789
+ expected = Series (np .array (vals ), dtype = any_int_numpy_dtype )
790
+ tm .assert_series_equal (res , expected )
791
+ alt = Series (np .array (vals )) # i.e. we ignore the dtype kwd
792
+ tm .assert_series_equal (alt , expected )
762
793
763
794
def test_constructor_coerce_float_valid (self , float_numpy_dtype ):
764
795
s = Series ([1 , 2 , 3.5 ], dtype = float_numpy_dtype )
765
796
expected = Series ([1 , 2 , 3.5 ]).astype (float_numpy_dtype )
766
797
tm .assert_series_equal (s , expected )
767
798
768
- def test_constructor_invalid_coerce_ints_with_float_nan (self , any_int_numpy_dtype ):
799
+ def test_constructor_invalid_coerce_ints_with_float_nan (
800
+ self , any_int_numpy_dtype , request
801
+ ):
769
802
# GH 22585
803
+ # Updated: make sure we treat this list the same as we would treat the
804
+ # equivalent ndarray
805
+ if np_version_under1p19 and np .dtype (any_int_numpy_dtype ).kind == "u" :
806
+ mark = pytest .mark .xfail (reason = "Produces an extra RuntimeWarning" )
807
+ request .node .add_marker (mark )
770
808
771
- msg = "cannot convert float NaN to integer"
772
- with pytest .raises (ValueError , match = msg ):
773
- Series ([1 , 2 , np .nan ], dtype = any_int_numpy_dtype )
809
+ vals = [1 , 2 , np .nan ]
810
+
811
+ msg = "In a future version, passing float-dtype values containing NaN"
812
+ with tm .assert_produces_warning (FutureWarning , match = msg ):
813
+ res = Series (vals , dtype = any_int_numpy_dtype )
814
+ with tm .assert_produces_warning (FutureWarning , match = msg ):
815
+ expected = Series (np .array (vals ), dtype = any_int_numpy_dtype )
816
+ tm .assert_series_equal (res , expected )
817
+ assert np .isnan (expected .iloc [- 1 ])
774
818
775
819
def test_constructor_dtype_no_cast (self ):
776
820
# see gh-1572
0 commit comments