@@ -932,6 +932,39 @@ def test_preserve_dtypes(op):
932
932
tm .assert_frame_equal (result , expected )
933
933
934
934
935
+ @pytest .mark .parametrize ("op" , ["min" , "max" ])
936
+ def test_preserve_dtypes_int64 (op ):
937
+ """ The above test case fails for large Int64s, so implement a better
938
+ version of the test for functions that properly preserve the dtype.
939
+ """
940
+ int64_iinfo = np .iinfo ("int64" )
941
+ df = pd .DataFrame (
942
+ {
943
+ "A" : ["a" , "b" , "b" ],
944
+ "B" : [1 , None , 3 ],
945
+ "C" : integer_array ([1 , None , 3 ], dtype = "Int64" ),
946
+ "D" : integer_array ([int64_iinfo .min , None , int64_iinfo .max ], dtype = "Int64" ),
947
+ }
948
+ )
949
+
950
+ # op
951
+ result = getattr (df .D , op )()
952
+ assert isinstance (result , int )
953
+
954
+ # groupby
955
+ result = getattr (df .groupby ("A" ), op )()
956
+
957
+ expected = pd .DataFrame (
958
+ {
959
+ "B" : np .array ([1.0 , 3.0 ]),
960
+ "C" : integer_array ([1 , 3 ], dtype = "Int64" ),
961
+ "D" : integer_array ([int64_iinfo .min , int64_iinfo .max ], dtype = "Int64" ),
962
+ },
963
+ index = pd .Index (["a" , "b" ], name = "A" ),
964
+ )
965
+ tm .assert_frame_equal (result , expected )
966
+
967
+
935
968
@pytest .mark .parametrize ("op" , ["mean" ])
936
969
def test_reduce_to_float (op ):
937
970
# some reduce ops always return float, even if the result
0 commit comments