Skip to content

Commit f463ef0

Browse files
dataxerikyehoshuadimarsky
authored andcommitted
ENH: Move CSSWarning to error/__init__.py per GH27656 (pandas-dev#47591)
* ENH: Move CSSWarning to error/__init__.py per GH27656 * ENH: fix typo * ENH: reword sentence
1 parent 8bb6ddb commit f463ef0

File tree

6 files changed

+25
-10
lines changed

6 files changed

+25
-10
lines changed

doc/source/reference/testing.rst

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Exceptions and warnings
2626

2727
errors.AbstractMethodError
2828
errors.AccessorRegistrationWarning
29+
errors.CSSWarning
2930
errors.DataError
3031
errors.DtypeWarning
3132
errors.DuplicateLabelError

pandas/errors/__init__.py

+18
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,21 @@ def __init__(self, message: str) -> None:
395395
# attr only exists on Windows, so typing fails on other platforms
396396
message += f" ({ctypes.WinError()})" # type: ignore[attr-defined]
397397
super().__init__(message)
398+
399+
400+
class CSSWarning(UserWarning):
401+
"""
402+
Warning is raised when converting css styling fails.
403+
This can be due to the styling not having an equivalent value or because the
404+
styling isn't properly formatted.
405+
406+
Examples
407+
--------
408+
>>> df = pd.DataFrame({'A': [1, 1, 1]})
409+
>>> df.style.applymap(lambda x: 'background-color: blueGreenRed;')
410+
... .to_excel('styled.xlsx') # doctest: +SKIP
411+
... # CSSWarning: Unhandled color format: 'blueGreenRed'
412+
>>> df.style.applymap(lambda x: 'border: 1px solid red red;')
413+
... .to_excel('styled.xlsx') # doctest: +SKIP
414+
... # CSSWarning: Too many tokens provided to "border" (expected 1-3)
415+
"""

pandas/io/formats/css.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@
1212
)
1313
import warnings
1414

15-
16-
class CSSWarning(UserWarning):
17-
"""
18-
This CSS syntax cannot currently be parsed.
19-
"""
15+
from pandas.errors import CSSWarning
2016

2117

2218
def _side_expander(prop_fmt: str) -> Callable:

pandas/tests/io/formats/test_css.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import pytest
22

3+
from pandas.errors import CSSWarning
4+
35
import pandas._testing as tm
46

5-
from pandas.io.formats.css import (
6-
CSSResolver,
7-
CSSWarning,
8-
)
7+
from pandas.io.formats.css import CSSResolver
98

109

1110
def assert_resolves(css, props, inherited=None):

pandas/tests/io/formats/test_to_excel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
import pytest
88

9+
from pandas.errors import CSSWarning
910
import pandas.util._test_decorators as td
1011

1112
import pandas._testing as tm
1213

13-
from pandas.io.formats.css import CSSWarning
1414
from pandas.io.formats.excel import (
1515
CssExcelCell,
1616
CSSToExcelConverter,

pandas/tests/test_errors.py

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"NumExprClobberingError",
3030
"IndexingError",
3131
"PyperclipException",
32+
"CSSWarning",
3233
],
3334
)
3435
def test_exception_importable(exc):

0 commit comments

Comments
 (0)