|
35 | 35 | import narwhals.stable.v1 as nw |
36 | 36 | from packaging.version import Version |
37 | 37 |
|
38 | | -# This leads to circular imports with the vegalite module. Currently, this works |
39 | | -# but be aware that when you access it in this script, the vegalite module might |
40 | | -# not yet be fully instantiated in case your code is being executed during import time |
41 | | -from altair import vegalite |
42 | | - |
43 | 38 | if sys.version_info >= (3, 12): |
44 | 39 | from typing import Protocol, TypeAliasType, runtime_checkable |
45 | 40 | else: |
@@ -709,6 +704,8 @@ def _get_altair_class_for_error( |
709 | 704 |
|
710 | 705 | This should lead to more informative error messages pointing the user closer to the source of the issue. |
711 | 706 | """ |
| 707 | + from altair import vegalite |
| 708 | + |
712 | 709 | for prop_name in reversed(error.absolute_path): |
713 | 710 | # Check if str as e.g. first item can be a 0 |
714 | 711 | if isinstance(prop_name, str): |
@@ -1597,14 +1594,15 @@ def __init__(self, prop: str, schema: dict[str, Any]) -> None: |
1597 | 1594 | self.schema = schema |
1598 | 1595 |
|
1599 | 1596 | def __get__(self, obj, cls): |
| 1597 | + from altair import vegalite |
| 1598 | + |
1600 | 1599 | self.obj = obj |
1601 | 1600 | self.cls = cls |
1602 | 1601 | # The docs from the encoding class parameter (e.g. `bin` in X, Color, |
1603 | 1602 | # etc); this provides a general description of the parameter. |
1604 | 1603 | self.__doc__ = self.schema["description"].replace("__", "**") |
1605 | 1604 | property_name = f"{self.prop}"[0].upper() + f"{self.prop}"[1:] |
1606 | | - if hasattr(vegalite, property_name): |
1607 | | - altair_prop = getattr(vegalite, property_name) |
| 1605 | + if altair_prop := getattr(vegalite, property_name, None): |
1608 | 1606 | # Add the docstring from the helper class (e.g. `BinParams`) so |
1609 | 1607 | # that all the parameter names of the helper class are included in |
1610 | 1608 | # the final docstring |
|
0 commit comments