@@ -1537,128 +1537,25 @@ def test_transform_sum_one_column_with_matching_labels_and_missing_labels():
15371537 tm .assert_frame_equal (result , expected )
15381538
15391539
1540- # GH#58084
1541- def test_min_one_unobserved_category_no_type_coercion ():
1540+ @pytest .mark .parametrize ("dtype" , ["int32" , "float32" ])
1541+ def test_min_one_unobserved_category_no_type_coercion (dtype ):
1542+ # GH#58084
15421543 df = DataFrame ({"A" : Categorical ([1 , 1 , 2 ], categories = [1 , 2 , 3 ]), "B" : [3 , 4 , 5 ]})
1543- df ["B" ] = df ["B" ].astype ("int32" )
1544+ df ["B" ] = df ["B" ].astype (dtype )
15441545 gb = df .groupby ("A" , observed = False )
15451546 result = gb .transform ("min" )
15461547
1547- expected = DataFrame ({"B" : [3 , 3 , 5 ]}, dtype = "int32" )
1548+ expected = DataFrame ({"B" : [3 , 3 , 5 ]}, dtype = dtype )
15481549 tm .assert_frame_equal (expected , result )
15491550
15501551
1551- # GH#58084
1552- def test_min_multiple_unobserved_categories_no_type_coercion ():
1553- df = DataFrame (
1554- {
1555- "X" : Categorical (
1556- ["432945" , "randomcat" , - 4325466 , "randomcat" , - 4325466 , - 4325466 ],
1557- categories = [
1558- 1 ,
1559- "randomcat" ,
1560- 100 ,
1561- 333 ,
1562- "cat43543" ,
1563- - 4325466 ,
1564- 54665 ,
1565- - 546767 ,
1566- "432945" ,
1567- 767076 ,
1568- ],
1569- ),
1570- "Y" : [0 , 940645 , np .iinfo (np .int64 ).min , 9449 , 100044444 , 40 ],
1571- }
1572- )
1573- df ["Y" ] = df ["Y" ].astype ("int64" )
1574-
1575- gb = df .groupby ("X" , observed = False )
1576- result = gb .transform ("min" )
1577-
1578- expected = DataFrame (
1579- {
1580- "Y" : [
1581- 0 ,
1582- 9449 ,
1583- np .iinfo (np .int64 ).min ,
1584- 9449 ,
1585- np .iinfo (np .int64 ).min ,
1586- np .iinfo (np .int64 ).min ,
1587- ]
1588- },
1589- dtype = "int64" ,
1590- )
1591- tm .assert_frame_equal (expected , result )
1592-
1593-
1594- # GH#58084
1595- def test_min_float32_multiple_unobserved_categories_no_type_coercion ():
1596- df = DataFrame (
1597- {
1598- "X" : Categorical (
1599- ["cat43543" , - 4325466 , 54665 , "cat43543" , - 4325466 , 54665 ],
1600- categories = [
1601- 1 ,
1602- "randomcat" ,
1603- 100 ,
1604- 333 ,
1605- "cat43543" ,
1606- - 4325466 ,
1607- 54665 ,
1608- - 546767 ,
1609- "432945" ,
1610- 767076 ,
1611- ],
1612- ),
1613- "Y" : [
1614- 0.3940429 ,
1615- 940645.49 ,
1616- np .finfo (np .float32 ).min ,
1617- 9449.03333 ,
1618- 100044444.403294 ,
1619- 40.3020909 ,
1620- ],
1621- }
1622- )
1623- df ["Y" ] = df ["Y" ].astype ("float32" )
1624-
1625- gb = df .groupby ("X" , observed = False )
1626- result = gb .transform ("min" )
1627-
1628- expected = DataFrame (
1629- {
1630- "Y" : [
1631- 0.3940429 ,
1632- 940645.49 ,
1633- np .finfo (np .float32 ).min ,
1634- 0.3940429 ,
1635- 940645.49 ,
1636- np .finfo (np .float32 ).min ,
1637- ]
1638- },
1639- dtype = "float32" ,
1640- )
1641- tm .assert_frame_equal (expected , result )
1642-
1643-
1644- # GH#58084
16451552def test_min_all_empty_data_no_type_coercion ():
1553+ # GH#58084
16461554 df = DataFrame (
16471555 {
16481556 "X" : Categorical (
16491557 [],
1650- categories = [
1651- 1 ,
1652- "randomcat" ,
1653- 100 ,
1654- 333 ,
1655- "cat43543" ,
1656- - 4325466 ,
1657- 54665 ,
1658- - 546767 ,
1659- "432945" ,
1660- 767076 ,
1661- ],
1558+ categories = [1 , "randomcat" , 100 ],
16621559 ),
16631560 "Y" : [],
16641561 }
@@ -1672,8 +1569,8 @@ def test_min_all_empty_data_no_type_coercion():
16721569 tm .assert_frame_equal (expected , result )
16731570
16741571
1675- # GH#58084
16761572def test_min_one_dim_no_type_coercion ():
1573+ # GH#58084
16771574 df = DataFrame ({"Y" : [9435 , - 5465765 , 5055 , 0 , 954960 ]})
16781575 df ["Y" ] = df ["Y" ].astype ("int32" )
16791576 categories = Categorical ([1 , 2 , 2 , 5 , 1 ], categories = [1 , 2 , 3 , 4 , 5 ])
0 commit comments