@@ -149,3 +149,37 @@ def test_adorn_percentages_with_ns_all():
149149 # Should have more than one column (including percentages and raw counts)
150150 assert "(" in result .iloc [0 , 1 ]
151151 # Check that raw counts are included
152+
153+
154+ @pytest .mark .functions
155+ def test_adorn_percentages_empty_pivot ():
156+ """
157+ Test that adorn_percentages returns an empty DataFrame if the pivot is empty.
158+ """
159+ # DataFrame sans colonnes valides pour le pivot
160+ data = {"NonExistentColumn" : [], "AnotherColumn" : [], "Value" : []}
161+ df = pd .DataFrame (data )
162+
163+ # Appel de la fonction avec des colonnes inexistantes
164+ result = adorn_percentages (df , "NonExistentColumn" , "AnotherColumn" )
165+
166+ # Vérifie que le résultat est un DataFrame vide
167+ assert result .empty , "Expected an empty DataFrame when pivot is empty."
168+
169+
170+ @pytest .mark .functions
171+ def test_adorn_percentages_invalid_axis ():
172+ """
173+ Test that adorn_percentages raises a ValueError for an invalid axis argument.
174+ """
175+ data = {
176+ "Category" : ["A" , "B" ],
177+ "Subcategory" : ["X" , "Y" ],
178+ "Value" : [10 , 20 ],
179+ }
180+ df = pd .DataFrame (data )
181+
182+ with pytest .raises (
183+ ValueError , match = "The 'axis' argument must be 'row', 'col', or 'all'."
184+ ):
185+ adorn_percentages (df , "Category" , "Subcategory" , axis = "invalid" )
0 commit comments