@@ -1162,13 +1162,16 @@ def test_describe(self):
11621162 self .assertEqual (desc .loc ['freq' ].tolist (), dfdesc .loc ['freq' ].tolist ())
11631163
11641164 # Percentiles
1165+ # Pandas < 3 always includes percentile 0.5 even if you don't ask for it
1166+ # Starting with Pandas 3, percentile 0.5 is not included unless you ask for it
1167+ # CASTable always includes 0.5, regardless of pandas version.
11651168 desc = self .table .describe (percentiles = [0.3 , 0.7 ])
1166- dfdesc = df .describe (percentiles = [0.3 , 0.7 ])
1169+ dfdesc = df .describe (percentiles = [0.3 , 0.5 , 0. 7 ])
11671170 self .assertEqual (desc .index .tolist (), dfdesc .index .tolist ())
11681171 self .assertEqual (desc .columns .tolist (), dfdesc .columns .tolist ())
11691172
11701173 desc = self .table .describe (percentiles = 0.4 )
1171- dfdesc = df .describe (percentiles = [0.4 ])
1174+ dfdesc = df .describe (percentiles = [0.4 , 0.5 ])
11721175 self .assertEqual (desc .index .tolist (), dfdesc .index .tolist ())
11731176 self .assertEqual (desc .columns .tolist (), dfdesc .columns .tolist ())
11741177
@@ -1536,17 +1539,39 @@ def test_mode(self):
15361539 tblgrp = tbl [['Make' , 'Type' ]].groupby (['Make' ])
15371540
15381541 # TODO: Pandas mode sets columns with all unique values to NaN
1539- self .assertEqual (
1540- dfgrp .get_group ('Acura' ).mode ()[['Type' ]].to_csv (index = False ),
1541- tblgrp .mode ().loc ['Acura' , ['Type' ]].dropna (how = 'all' ).to_csv (index = False ))
1542+ if pd_version >= (2 , 2 , 0 ):
1543+ # Syntax Change in pandas 3.
1544+ # Future Warning in Pandas 2.2+
1545+ # When grouping with a length-1 list-like,
1546+ # you will need to pass a length-1 tuple to get_group
1547+ self .assertEqual (
1548+ dfgrp .get_group (('Acura' ,)).mode ()[['Type' ]].to_csv (index = False ),
1549+ tblgrp .mode ().loc ['Acura' , ['Type' ]].dropna (how = 'all' )
1550+ .to_csv (index = False ))
1551+ else :
1552+ self .assertEqual (
1553+ dfgrp .get_group ('Acura' ).mode ()[['Type' ]].to_csv (index = False ),
1554+ tblgrp .mode ().loc ['Acura' , ['Type' ]].dropna (how = 'all' )
1555+ .to_csv (index = False ))
15421556
15431557 dfgrp = df [['Cylinders' , 'MPG_City' ]].groupby (['Cylinders' ])
15441558 tblgrp = tbl [['Cylinders' , 'MPG_City' ]].groupby (['Cylinders' ])
15451559
15461560 # TODO: Pandas mode sets columns with all unique values to NaN
1547- self .assertEqual (
1548- dfgrp .get_group (6.0 ).mode ()[['MPG_City' ]].to_csv (index = False ),
1549- tblgrp .mode ().loc [6.0 , ['MPG_City' ]].dropna (how = 'all' ).to_csv (index = False ))
1561+ if pd_version >= (2 , 2 , 0 ):
1562+ # Syntax Change in pandas 3.
1563+ # Future Warning in Pandas 2.2+
1564+ # When grouping with a length-1 list-like,
1565+ # you will need to pass a length-1 tuple to get_group
1566+ self .assertEqual (
1567+ dfgrp .get_group ((6.0 ,)).mode ()[['MPG_City' ]].to_csv (index = False ),
1568+ tblgrp .mode ().loc [6.0 , ['MPG_City' ]].dropna (how = 'all' )
1569+ .to_csv (index = False ))
1570+ else :
1571+ self .assertEqual (
1572+ dfgrp .get_group (6.0 ).mode ()[['MPG_City' ]].to_csv (index = False ),
1573+ tblgrp .mode ().loc [6.0 , ['MPG_City' ]].dropna (how = 'all' )
1574+ .to_csv (index = False ))
15501575
15511576 def test_median (self ):
15521577 df = self .get_cars_df ()
@@ -4652,7 +4677,9 @@ def test_to_html(self):
46524677
46534678 html = tbl .to_html (index = False )
46544679
4655- df2 = pd .read_html (html )[0 ]
4680+ # Starting with Pandas 3 you can no longer
4681+ # pass an html string to pandas read_html.
4682+ df2 = pd .read_html (io .StringIO (html ))[0 ]
46564683
46574684 df ['Model' ] = df ['Model' ].str .strip ()
46584685
0 commit comments