Skip to content

Commit c7b5174

Browse files
committed
New test for method
1 parent ae5e27f commit c7b5174

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

tests/test_accessor.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,32 @@
99
import xarray as xr
1010

1111
import xarray_plotly # noqa: F401 - registers accessor
12+
from xarray_plotly import xpx
13+
14+
15+
class TestXpxFunction:
16+
"""Tests for the xpx() function."""
17+
18+
def test_xpx_returns_accessor(self) -> None:
19+
"""Test that xpx() returns a DataArrayPlotlyAccessor."""
20+
da = xr.DataArray(np.random.rand(10), dims=["time"])
21+
accessor = xpx(da)
22+
assert hasattr(accessor, "line")
23+
assert hasattr(accessor, "bar")
24+
assert hasattr(accessor, "scatter")
25+
26+
def test_xpx_equivalent_to_accessor(self) -> None:
27+
"""Test that xpx(da).line() works the same as da.plotly.line()."""
28+
da = xr.DataArray(
29+
np.random.rand(10, 3),
30+
dims=["time", "city"],
31+
coords={"time": np.arange(10), "city": ["A", "B", "C"]},
32+
name="test",
33+
)
34+
fig1 = xpx(da).line()
35+
fig2 = da.plotly.line()
36+
assert isinstance(fig1, go.Figure)
37+
assert isinstance(fig2, go.Figure)
1238

1339

1440
class TestDataArrayPxplot:

xarray_plotly/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
"""
2-
xarray_plotly: Interactive Plotly Express plotting accessor for xarray.
2+
xarray_plotly: Interactive Plotly Express plotting for xarray.
33
4-
This package provides a `plotly` accessor for xarray DataArray objects that
5-
enables interactive plotting using Plotly Express.
4+
This package provides interactive plotting for xarray DataArray objects
5+
using Plotly Express.
66
77
Examples
88
--------
99
>>> import xarray as xr
1010
>>> import numpy as np
11-
>>> import xarray_plotly # registers the accessor
11+
>>> from xarray_plotly import xpx
1212
1313
>>> da = xr.DataArray(
1414
... np.random.rand(10, 3, 2),
1515
... dims=["time", "city", "scenario"],
1616
... )
1717
1818
>>> # Auto-assignment: time->x, city->color, scenario->facet_col
19-
>>> fig = da.plotly.line()
19+
>>> fig = xpx(da).line()
2020
2121
>>> # Explicit assignment
22-
>>> fig = da.plotly.line(x="time", color="scenario", facet_col="city")
22+
>>> fig = xpx(da).line(x="time", color="scenario", facet_col="city")
2323
2424
>>> # Skip a slot
25-
>>> fig = da.plotly.line(color=None) # time->x, city->facet_col, scenario->facet_row
25+
>>> fig = xpx(da).line(color=None) # time->x, city->facet_col, scenario->facet_row
2626
"""
2727

2828
from importlib.metadata import version

0 commit comments

Comments
 (0)