Skip to content

Commit

Permalink
fix is_array check
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjinliu committed Sep 25, 2024
1 parent 6955bdf commit 1ac55d4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
4 changes: 4 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ def backend(request: pytest.FixtureRequest):
request.param.param = backend
else:
if getattr(request.function, "failed", None) == "mock":
_cleanup(request)
pytest.fail("Failed in mock backend")
yield request.param

if request.node.rep_call.failed:
request.function.failed = request.param
_cleanup(request)

def _cleanup(request: pytest.FixtureRequest):
if request.param == "matplotlib":
plt.close("all")
elif request.param == "pyqtgraph":
Expand Down
16 changes: 8 additions & 8 deletions whitecanvas/layers/_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ def with_face(
self,
color: ColorType | _Void = _void,
hatch: Hatch | str = Hatch.SOLID,
alpha: float = 1,
alpha: float | _Void = _void,
) -> Self:
"""Update the face properties."""
if is_array(hatch) or is_array(alpha):
Expand All @@ -670,7 +670,7 @@ def with_edge(
color: ColorType | None = None,
width: float = 1.0,
style: LineStyle | str = LineStyle.SOLID,
alpha: float = 1,
alpha: float | _Void = _void,
) -> Self:
"""Update the edge properties."""
if is_array(width) or is_array(style) or is_array(alpha):
Expand All @@ -690,7 +690,7 @@ def with_face_multi(
self,
color: ColorType | Sequence[ColorType] | _Void = _void,
hatch: str | Hatch | Sequence[str | Hatch] | _Void = _void,
alpha: float = 1,
alpha: float | _Void = _void,
) -> Self:
if not isinstance(self._face_namespace, MultiFace):
self._face_namespace.events.disconnect()
Expand All @@ -704,7 +704,7 @@ def with_edge_multi(
color: ColorType | Sequence[ColorType] | None = None,
width: float | Sequence[float] = 1,
style: str | LineStyle | list[str | LineStyle] = LineStyle.SOLID,
alpha: float = 1,
alpha: float | _Void = _void,
) -> Self:
"""Update the edge properties."""
if color is None:
Expand Down Expand Up @@ -1051,7 +1051,7 @@ def with_face(
*,
color: ColorType | _Void = _void,
hatch: Hatch | str = Hatch.SOLID,
alpha: float = 1,
alpha: float | _Void = _void,
) -> Self:
"""Update the face properties."""
if is_array(hatch) or is_array(alpha):
Expand All @@ -1069,7 +1069,7 @@ def with_edge(
color: ColorType | None = None,
width: float = 1.0,
style: LineStyle | str = LineStyle.SOLID,
alpha: float = 1,
alpha: float | _Void = _void,
) -> Self:
"""Update the edge properties."""
if is_array(width) or is_array(style) or is_array(alpha):
Expand All @@ -1090,7 +1090,7 @@ def with_face_multi(
*,
color: ColorType | Sequence[ColorType] | _Void = _void,
hatch: str | Hatch | Sequence[str | Hatch] = Hatch.SOLID,
alpha: float = 1,
alpha: float | _Void = _void,
) -> Self:
if not isinstance(self._face_namespace, MultiFace):
self._face_namespace.events.disconnect()
Expand All @@ -1105,7 +1105,7 @@ def with_edge_multi(
color: ColorType | Sequence[ColorType] | None = None,
width: float | Sequence[float] = 1,
style: str | LineStyle | list[str | LineStyle] = LineStyle.SOLID,
alpha: float = 1,
alpha: float | _Void = _void,
) -> Self:
"""Update the edge properties."""
if color is None:
Expand Down
8 changes: 4 additions & 4 deletions whitecanvas/layers/_primitive/bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def with_face(
*,
color: ColorType | _Void = _void,
hatch: Hatch | str = Hatch.SOLID,
alpha: float = 1,
alpha: float | _Void = _void,
) -> Bars[ConstFace, _Edge]:
return super().with_face(color=color, hatch=hatch, alpha=alpha)

Expand All @@ -394,7 +394,7 @@ def with_face_multi(
*,
color: ColorType | Sequence[ColorType] | _Void = _void,
hatch: str | Hatch | Sequence[str | Hatch] | _Void = _void,
alpha: float = 1,
alpha: float | _Void = _void,
) -> Bars[MultiFace, _Edge]:
return super().with_face_multi(color=color, hatch=hatch, alpha=alpha)

Expand All @@ -404,7 +404,7 @@ def with_edge(
color: ColorType | None = None,
width: float = 1,
style: LineStyle | str = LineStyle.SOLID,
alpha: float = 1,
alpha: float | _Void = _void,
) -> Bars[_Face, ConstEdge]:
return super().with_edge(color=color, width=width, style=style, alpha=alpha)

Expand All @@ -414,7 +414,7 @@ def with_edge_multi(
color: ColorType | Sequence[ColorType] | None = None,
width: float | Sequence[float] = 1,
style: str | LineStyle | list[str | LineStyle] = LineStyle.SOLID,
alpha: float = 1,
alpha: float | _Void = _void,
) -> Bars[_Face, MultiEdge]:
return super().with_edge_multi(
color=color, width=width, style=style, alpha=alpha
Expand Down
2 changes: 1 addition & 1 deletion whitecanvas/layers/group/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def with_text(
@classmethod
def from_dict(cls, d: dict[str, Any], backend: Backend | str | None = None) -> Self:
children = construct_layers(d["children"], backend=backend)
if (offset := d.get("offset")) is not None:
if isinstance(offset := d.get("offset"), dict):
offset = parse_offset_dict(offset)
return cls(*children, name=d.get("name"), offset=offset)

Expand Down
2 changes: 1 addition & 1 deletion whitecanvas/layers/group/labeled.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _default_ordering(self, n: int) -> list[int]:
@classmethod
def from_dict(cls, d: dict[str, Any], backend: Backend | str | None = None) -> Self:
children = construct_layers(d["children"], backend=backend)
if (offset := d.get("offset")) is not None:
if isinstance(offset := d.get("offset"), dict):
offset = parse_offset_dict(offset)
return cls(*children, name=d.get("name"), offset=offset)

Expand Down
4 changes: 3 additions & 1 deletion whitecanvas/utils/type_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import numpy as np

from whitecanvas.types import _Void

if TYPE_CHECKING:
import pandas as pd
import polars as pl
Expand All @@ -15,7 +17,7 @@

def is_array(x) -> bool:
"""True if x is an array that needs multi-face/edge."""
return not is_not_array(x)
return not (is_not_array(x) or isinstance(x, _Void))


def is_not_array(x) -> bool:
Expand Down

0 comments on commit 1ac55d4

Please sign in to comment.