Skip to content

ENH: Move CSSWarning to error/__init__.py per GH27656 #47591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/reference/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Exceptions and warnings

errors.AbstractMethodError
errors.AccessorRegistrationWarning
errors.CSSWarning
errors.DataError
errors.DtypeWarning
errors.DuplicateLabelError
Expand Down
18 changes: 18 additions & 0 deletions pandas/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,21 @@ def __init__(self, message: str) -> None:
# attr only exists on Windows, so typing fails on other platforms
message += f" ({ctypes.WinError()})" # type: ignore[attr-defined]
super().__init__(message)


class CSSWarning(UserWarning):
"""
Warning is raised when trying to convert styling to a css format and it failing.
This can be due to the styling not having an equivalent value or because the
styling isn't properly formatted.

Examples
--------
>>> df = pd.DataFrame({'A': [1, 1, 1]})
>>> df.style.applymap(lambda x: 'background-color: blueGreenRed;')
... .to_excel('styled.xlsx') # doctest: +SKIP
... # CSSWarning: Unhandled color format: 'blueGreenRed'
>>> df.style.applymap(lambda x: 'border: 1px solid red red;')
... .to_excel('styled.xlsx') # doctest: +SKIP
... # CSSWarning: Too many tokens provided to "border" (expected 1-3)
"""
6 changes: 1 addition & 5 deletions pandas/io/formats/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
)
import warnings


class CSSWarning(UserWarning):
"""
This CSS syntax cannot currently be parsed.
"""
from pandas.errors import CSSWarning


def _side_expander(prop_fmt: str) -> Callable:
Expand Down
7 changes: 3 additions & 4 deletions pandas/tests/io/formats/test_css.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import pytest

from pandas.errors import CSSWarning

import pandas._testing as tm

from pandas.io.formats.css import (
CSSResolver,
CSSWarning,
)
from pandas.io.formats.css import CSSResolver


def assert_resolves(css, props, inherited=None):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/formats/test_to_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import pytest

from pandas.errors import CSSWarning
import pandas.util._test_decorators as td

import pandas._testing as tm

from pandas.io.formats.css import CSSWarning
from pandas.io.formats.excel import (
CssExcelCell,
CSSToExcelConverter,
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"NumExprClobberingError",
"IndexingError",
"PyperclipException",
"CSSWarning",
],
)
def test_exception_importable(exc):
Expand Down