-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
testcore.py
71 lines (54 loc) · 1.9 KB
/
testcore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import numpy as np
import pandas as pd
import hvplot.pandas # noqa
import pytest
try:
import polars as pl
import hvplot.polars # noqa
pl_import = True
except ImportError:
class pl:
DataFrame = None
LazyFrame = None
Series = None
pl_import = False
FRAME_IGNORE_TYPES = {"bivariate", "heatmap", "hexbin", "labels", "vectorfield"}
SERIES_IGNORE_TYPES = {*FRAME_IGNORE_TYPES, "points", "polygons", "ohlc", "paths"}
y_combinations = pytest.mark.parametrize("y", (
["A", "B", "C", "D"],
("A", "B", "C", "D"),
{"A", "B", "C", "D"},
np.array(["A", "B", "C", "D"]),
pd.Index(["A", "B", "C", "D"]),
pd.Series(["A", "B", "C", "D"]),
),
ids=lambda x: type(x).__name__
)
@y_combinations
def test_diffent_input_types_pandas(y):
df = pd._testing.makeDataFrame()
types = {t for t in dir(df.hvplot) if not t.startswith("_")}
for t in types - FRAME_IGNORE_TYPES:
df.hvplot(y=y, kind=t)
def test_series_pandas():
ser = pd.Series(np.random.rand(10), name="A")
assert isinstance(ser, pd.Series)
types = {t for t in dir(ser.hvplot) if not t.startswith("_")}
for t in types - SERIES_IGNORE_TYPES:
ser.hvplot(kind=t)
@pytest.mark.skipif(pl_import, reason="polars not installed")
@pytest.mark.parametrize("cast", (pl.DataFrame, pl.LazyFrame))
@y_combinations
def test_diffent_input_types_polars(y, cast):
df = cast(pd._testing.makeDataFrame())
assert isinstance(df, cast)
types = {t for t in dir(df.hvplot) if not t.startswith("_")}
for t in types - FRAME_IGNORE_TYPES:
df.hvplot(y=y, kind=t)
@pytest.mark.skipif(pl_import, reason="polars not installed")
def test_series_polars():
ser = pl.Series(values=np.random.rand(10), name="A")
assert isinstance(ser, pl.Series)
types = {t for t in dir(ser.hvplot) if not t.startswith("_")}
for t in types - SERIES_IGNORE_TYPES:
ser.hvplot(kind=t)