@@ -1747,107 +1747,4 @@ def test_html_formatter_manual_format_html(clean_formatter_state):
17471747 local_html_2 = local_formatter .format_html ([batch ], batch .schema )
17481748
17491749 assert "<style>" in local_html_1
1750- assert "<style>" in local_html_2
1751-
1752-
1753- def test_html_formatter_memory_and_rows ():
1754- """Test the memory and row control parameters in DataFrameHtmlFormatter."""
1755-
1756- # Test default values
1757- formatter = DataFrameHtmlFormatter ()
1758- assert formatter .max_memory_bytes == 2 * 1024 * 1024 # 2 MB
1759- assert formatter .min_rows_display == 20
1760- assert formatter .repr_rows == 10
1761-
1762- # Test custom values
1763- formatter = DataFrameHtmlFormatter (
1764- max_memory_bytes = 1024 * 1024 , # 1 MB
1765- min_rows_display = 10 ,
1766- repr_rows = 5
1767- )
1768- assert formatter .max_memory_bytes == 1024 * 1024
1769- assert formatter .min_rows_display == 10
1770- assert formatter .repr_rows == 5
1771-
1772- # Test extremely large values and tiny values (edge cases)
1773- # These should not raise exceptions
1774- extreme_formatter = DataFrameHtmlFormatter (
1775- max_memory_bytes = 10 * 1024 * 1024 * 1024 , # 10 GB
1776- min_rows_display = 1 ,
1777- repr_rows = 1
1778- )
1779- assert extreme_formatter .max_memory_bytes == 10 * 1024 * 1024 * 1024
1780- assert extreme_formatter .min_rows_display == 1
1781- assert extreme_formatter .repr_rows == 1
1782-
1783- # Test validation for invalid parameters
1784- with pytest .raises (ValueError , match = "max_memory_bytes must be a positive integer" ):
1785- DataFrameHtmlFormatter (max_memory_bytes = 0 )
1786-
1787- with pytest .raises (ValueError , match = "max_memory_bytes must be a positive integer" ):
1788- DataFrameHtmlFormatter (max_memory_bytes = - 100 )
1789-
1790- with pytest .raises (ValueError , match = "min_rows_display must be a positive integer" ):
1791- DataFrameHtmlFormatter (min_rows_display = 0 )
1792-
1793- with pytest .raises (ValueError , match = "min_rows_display must be a positive integer" ):
1794- DataFrameHtmlFormatter (min_rows_display = - 5 )
1795-
1796- with pytest .raises (ValueError , match = "repr_rows must be a positive integer" ):
1797- DataFrameHtmlFormatter (repr_rows = 0 )
1798-
1799- with pytest .raises (ValueError , match = "repr_rows must be a positive integer" ):
1800- DataFrameHtmlFormatter (repr_rows = - 10 )
1801-
1802-
1803- def test_html_formatter_custom_style_provider_with_parameters (df , clean_formatter_state ):
1804- """Test using custom style providers with the HTML formatter and configured parameters."""
1805-
1806- class CustomStyleProvider :
1807- def get_cell_style (self ) -> str :
1808- return (
1809- "background-color: #f5f5f5; color: #333; padding: 8px; border: "
1810- "1px solid #ddd;"
1811- )
1812-
1813- def get_header_style (self ) -> str :
1814- return (
1815- "background-color: #4285f4; color: white; font-weight: bold; "
1816- "padding: 10px; border: 1px solid #3367d6;"
1817- )
1818-
1819- # Configure with custom style provider
1820- configure_formatter (style_provider = CustomStyleProvider ())
1821-
1822- html_output = df ._repr_html_ ()
1823-
1824- # Verify our custom styles were applied
1825- assert "background-color: #4285f4" in html_output
1826- assert "color: white" in html_output
1827- assert "background-color: #f5f5f5" in html_output
1828-
1829- # Reset for the next part of the test
1830- reset_formatter ()
1831-
1832- # Configure with custom style provider and additional parameters
1833- configure_formatter (
1834- style_provider = CustomStyleProvider (),
1835- max_memory_bytes = 3 * 1024 * 1024 , # 3 MB
1836- min_rows_display = 15 ,
1837- repr_rows = 7
1838- )
1839-
1840- html_output = df ._repr_html_ ()
1841-
1842- # Verify our custom styles were applied
1843- assert "background-color: #4285f4" in html_output
1844- assert "color: white" in html_output
1845- assert "background-color: #f5f5f5" in html_output
1846-
1847- # Test memory and row parameters were properly set
1848- formatter = get_formatter ()
1849- assert formatter .max_memory_bytes == 3 * 1024 * 1024 # 3 MB
1850- assert formatter .min_rows_display == 15
1851- assert formatter .repr_rows == 7
1852-
1853-
1750+ assert "<style>" in local_html_2
0 commit comments