hvplot 0.9.3a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hvplot/__init__.py +322 -0
- hvplot/_version.py +16 -0
- hvplot/backend_transforms.py +329 -0
- hvplot/converter.py +2855 -0
- hvplot/cudf.py +26 -0
- hvplot/dask.py +42 -0
- hvplot/data/crime.csv +56 -0
- hvplot/datasets.yaml +48 -0
- hvplot/fugue.py +64 -0
- hvplot/ibis.py +21 -0
- hvplot/intake.py +32 -0
- hvplot/interactive.py +968 -0
- hvplot/networkx.py +625 -0
- hvplot/pandas.py +30 -0
- hvplot/plotting/__init__.py +63 -0
- hvplot/plotting/andrews_curves.py +99 -0
- hvplot/plotting/core.py +2288 -0
- hvplot/plotting/lag_plot.py +34 -0
- hvplot/plotting/parallel_coordinates.py +85 -0
- hvplot/plotting/scatter_matrix.py +220 -0
- hvplot/polars.py +21 -0
- hvplot/sample_data.py +30 -0
- hvplot/streamz.py +21 -0
- hvplot/tests/__init__.py +0 -0
- hvplot/tests/conftest.py +44 -0
- hvplot/tests/data/README.md +5 -0
- hvplot/tests/data/RGB-red.byte.tif +0 -0
- hvplot/tests/plotting/__init__.py +0 -0
- hvplot/tests/plotting/testcore.py +108 -0
- hvplot/tests/plotting/testohlc.py +34 -0
- hvplot/tests/plotting/testscattermatrix.py +138 -0
- hvplot/tests/test_links.py +99 -0
- hvplot/tests/testbackend_transforms.py +89 -0
- hvplot/tests/testcharts.py +452 -0
- hvplot/tests/testfugue.py +46 -0
- hvplot/tests/testgeo.py +468 -0
- hvplot/tests/testgeowithoutgv.py +60 -0
- hvplot/tests/testgridplots.py +259 -0
- hvplot/tests/testhelp.py +75 -0
- hvplot/tests/testibis.py +17 -0
- hvplot/tests/testinteractive.py +1442 -0
- hvplot/tests/testnetworkx.py +26 -0
- hvplot/tests/testoperations.py +385 -0
- hvplot/tests/testoptions.py +596 -0
- hvplot/tests/testoverrides.py +74 -0
- hvplot/tests/testpanel.py +70 -0
- hvplot/tests/testpatch.py +135 -0
- hvplot/tests/testplotting.py +69 -0
- hvplot/tests/teststreaming.py +28 -0
- hvplot/tests/testtransforms.py +39 -0
- hvplot/tests/testui.py +383 -0
- hvplot/tests/testutil.py +378 -0
- hvplot/tests/util.py +82 -0
- hvplot/ui.py +1032 -0
- hvplot/util.py +677 -0
- hvplot/utilities.py +129 -0
- hvplot/xarray.py +62 -0
- hvplot-0.9.3a1.dist-info/LICENSE +29 -0
- hvplot-0.9.3a1.dist-info/METADATA +243 -0
- hvplot-0.9.3a1.dist-info/RECORD +63 -0
- hvplot-0.9.3a1.dist-info/WHEEL +5 -0
- hvplot-0.9.3a1.dist-info/entry_points.txt +2 -0
- hvplot-0.9.3a1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
from unittest import SkipTest, expectedFailure
|
|
4
|
+
from parameterized import parameterized
|
|
5
|
+
|
|
6
|
+
from holoviews.core.dimension import Dimension
|
|
7
|
+
from holoviews import NdOverlay, Store, dim, render
|
|
8
|
+
from holoviews.element import Curve, Area, Scatter, Points, Path, HeatMap
|
|
9
|
+
from holoviews.element.comparison import ComparisonTestCase
|
|
10
|
+
|
|
11
|
+
from ..util import is_dask
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TestChart2D(ComparisonTestCase):
|
|
15
|
+
def setUp(self):
|
|
16
|
+
try:
|
|
17
|
+
import pandas as pd
|
|
18
|
+
except ImportError:
|
|
19
|
+
raise SkipTest('Pandas not available')
|
|
20
|
+
import hvplot.pandas # noqa
|
|
21
|
+
|
|
22
|
+
self.df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], columns=['x', 'y'])
|
|
23
|
+
self.cat_df = pd.DataFrame(
|
|
24
|
+
[[1, 2, 'A'], [3, 4, 'B'], [5, 6, 'C']], columns=['x', 'y', 'category']
|
|
25
|
+
)
|
|
26
|
+
self.time_df = pd.DataFrame(
|
|
27
|
+
{
|
|
28
|
+
'time': pd.date_range('1/1/2000', periods=5 * 24, freq='1h', tz='UTC'),
|
|
29
|
+
'temp': np.sin(np.linspace(0, 5 * 2 * np.pi, 5 * 24)).cumsum(),
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
@parameterized.expand([('points', Points), ('paths', Path)])
|
|
34
|
+
def test_2d_defaults(self, kind, element):
|
|
35
|
+
plot = self.df.hvplot(kind=kind)
|
|
36
|
+
self.assertEqual(plot, element(self.df, ['x', 'y']))
|
|
37
|
+
|
|
38
|
+
@parameterized.expand([('points', Points), ('paths', Path)])
|
|
39
|
+
def test_2d_chart(self, kind, element):
|
|
40
|
+
plot = self.df.hvplot(x='x', y='y', kind=kind)
|
|
41
|
+
self.assertEqual(plot, element(self.df, ['x', 'y']))
|
|
42
|
+
|
|
43
|
+
@parameterized.expand([('points', Points), ('paths', Path)])
|
|
44
|
+
def test_2d_index_and_c(self, kind, element):
|
|
45
|
+
plot = self.df.hvplot(x='index', y='y', c='x', kind=kind)
|
|
46
|
+
self.assertEqual(plot, element(self.df, ['index', 'y'], ['x']))
|
|
47
|
+
|
|
48
|
+
@parameterized.expand([('points', Points), ('paths', Path)])
|
|
49
|
+
def test_2d_set_hover_cols_to_list(self, kind, element):
|
|
50
|
+
plot = self.cat_df.hvplot(x='x', y='y', hover_cols=['category'], kind=kind)
|
|
51
|
+
self.assertEqual(plot, element(self.cat_df, ['x', 'y'], ['category']))
|
|
52
|
+
|
|
53
|
+
@parameterized.expand([('points', Points), ('paths', Path)])
|
|
54
|
+
def test_2d_set_hover_cols_including_index(self, kind, element):
|
|
55
|
+
plot = self.cat_df.hvplot(x='x', y='y', hover_cols=['index'], kind=kind)
|
|
56
|
+
data = plot.data[0] if kind == 'paths' else plot.data
|
|
57
|
+
assert 'index' in data.columns
|
|
58
|
+
self.assertEqual(plot, element(self.cat_df.reset_index(), ['x', 'y'], ['index']))
|
|
59
|
+
|
|
60
|
+
@parameterized.expand([('points', Points), ('paths', Path)])
|
|
61
|
+
def test_2d_set_hover_cols_to_all(self, kind, element):
|
|
62
|
+
plot = self.cat_df.hvplot(x='x', y='y', hover_cols='all', kind=kind)
|
|
63
|
+
data = plot.data[0] if kind == 'paths' else plot.data
|
|
64
|
+
assert 'index' in data.columns
|
|
65
|
+
self.assertEqual(
|
|
66
|
+
plot, element(self.cat_df.reset_index(), ['x', 'y'], ['index', 'category'])
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
@parameterized.expand([('points', Points), ('paths', Path)])
|
|
70
|
+
def test_2d_set_hover_cols_to_all_with_use_index_as_false(self, kind, element):
|
|
71
|
+
plot = self.cat_df.hvplot(x='x', y='y', hover_cols='all', use_index=False, kind=kind)
|
|
72
|
+
self.assertEqual(plot, element(self.cat_df, ['x', 'y'], ['category']))
|
|
73
|
+
|
|
74
|
+
def test_heatmap_2d_index_columns(self):
|
|
75
|
+
plot = self.df.hvplot.heatmap()
|
|
76
|
+
self.assertEqual(
|
|
77
|
+
plot, HeatMap((['x', 'y'], [0, 1, 2], self.df.values), ['columns', 'index'], 'value')
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
def test_heatmap_2d_derived_x_and_y(self):
|
|
81
|
+
plot = self.time_df.hvplot.heatmap(x='time.hour', y='time.day', C='temp')
|
|
82
|
+
assert plot.kdims == ['time.hour', 'time.day']
|
|
83
|
+
assert plot.vdims == ['temp']
|
|
84
|
+
|
|
85
|
+
def test_xarray_dataset_with_attrs(self):
|
|
86
|
+
try:
|
|
87
|
+
import xarray as xr
|
|
88
|
+
import hvplot.xarray # noqa
|
|
89
|
+
except ImportError:
|
|
90
|
+
raise SkipTest('xarray not available')
|
|
91
|
+
|
|
92
|
+
dset = xr.Dataset(
|
|
93
|
+
{'u': ('t', [1, 3]), 'v': ('t', [4, 2])},
|
|
94
|
+
coords={'t': ('t', [0, 1], {'long_name': 'time', 'units': 's'})},
|
|
95
|
+
)
|
|
96
|
+
ndoverlay = dset.hvplot.line()
|
|
97
|
+
|
|
98
|
+
assert render(ndoverlay, 'bokeh').xaxis.axis_label == 'time (s)'
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class TestChart2DDask(TestChart2D):
|
|
102
|
+
def setUp(self):
|
|
103
|
+
super().setUp()
|
|
104
|
+
try:
|
|
105
|
+
import dask.dataframe as dd
|
|
106
|
+
except ImportError:
|
|
107
|
+
raise SkipTest('Dask not available')
|
|
108
|
+
import hvplot.dask # noqa
|
|
109
|
+
|
|
110
|
+
self.df = dd.from_pandas(self.df, npartitions=2)
|
|
111
|
+
self.cat_df = dd.from_pandas(self.cat_df, npartitions=3)
|
|
112
|
+
|
|
113
|
+
@expectedFailure
|
|
114
|
+
def test_heatmap_2d_index_columns(self):
|
|
115
|
+
self.df.hvplot.heatmap()
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class TestChart1D(ComparisonTestCase):
|
|
119
|
+
def setUp(self):
|
|
120
|
+
try:
|
|
121
|
+
import pandas as pd
|
|
122
|
+
except ImportError:
|
|
123
|
+
raise SkipTest('Pandas not available')
|
|
124
|
+
import hvplot.pandas # noqa
|
|
125
|
+
|
|
126
|
+
self.df = pd.DataFrame([[1, 2], [3, 4], [5, 6]], columns=['x', 'y'])
|
|
127
|
+
self.df_desc = self.df.describe().transpose().sort_values('mean')
|
|
128
|
+
self.dt_df = pd.DataFrame(
|
|
129
|
+
np.random.rand(90), index=pd.date_range('2019-01-01', '2019-03-31')
|
|
130
|
+
)
|
|
131
|
+
self.cat_df = pd.DataFrame(
|
|
132
|
+
[[1, 2, 'A'], [3, 4, 'B'], [5, 6, 'C']], columns=['x', 'y', 'category']
|
|
133
|
+
)
|
|
134
|
+
self.cat_only_df = pd.DataFrame(
|
|
135
|
+
[['A', 'a'], ['B', 'b'], ['C', 'c']], columns=['upper', 'lower']
|
|
136
|
+
)
|
|
137
|
+
self.time_df = pd.DataFrame(
|
|
138
|
+
{
|
|
139
|
+
'time': pd.date_range('1/1/2000', periods=10, tz='UTC'),
|
|
140
|
+
'A': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
|
141
|
+
'B': list('abcdefghij'),
|
|
142
|
+
}
|
|
143
|
+
)
|
|
144
|
+
self.edge_df = pd.DataFrame(
|
|
145
|
+
{
|
|
146
|
+
'Latitude': [-34.58, -15.78, -33.45],
|
|
147
|
+
'Longitude': [-58.66, -47.91, -70.66],
|
|
148
|
+
'Volume {m3}': ['1', '2', '3'],
|
|
149
|
+
}
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
153
|
+
def test_wide_chart(self, kind, element):
|
|
154
|
+
plot = self.df.hvplot(kind=kind)
|
|
155
|
+
obj = NdOverlay(
|
|
156
|
+
{
|
|
157
|
+
'x': element(self.df, 'index', 'x').redim(x='value'),
|
|
158
|
+
'y': element(self.df, 'index', 'y').redim(y='value'),
|
|
159
|
+
},
|
|
160
|
+
'Variable',
|
|
161
|
+
)
|
|
162
|
+
self.assertEqual(plot, obj)
|
|
163
|
+
|
|
164
|
+
def test_by_datetime_accessor(self):
|
|
165
|
+
plot = self.dt_df.hvplot.line('index.dt.day', '0', by='index.dt.month')
|
|
166
|
+
obj = NdOverlay(
|
|
167
|
+
{
|
|
168
|
+
m: Curve((g.index.day, g[0]), 'index.dt.day', '0')
|
|
169
|
+
for m, g in self.dt_df.groupby(self.dt_df.index.month)
|
|
170
|
+
},
|
|
171
|
+
'index.dt.month',
|
|
172
|
+
)
|
|
173
|
+
self.assertEqual(plot, obj)
|
|
174
|
+
|
|
175
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
176
|
+
def test_wide_chart_labels(self, kind, element):
|
|
177
|
+
plot = self.df.hvplot(kind=kind, value_label='Test', group_label='Category')
|
|
178
|
+
obj = NdOverlay(
|
|
179
|
+
{
|
|
180
|
+
'x': element(self.df, 'index', 'x').redim(x='Test'),
|
|
181
|
+
'y': element(self.df, 'index', 'y').redim(y='Test'),
|
|
182
|
+
},
|
|
183
|
+
'Category',
|
|
184
|
+
)
|
|
185
|
+
self.assertEqual(plot, obj)
|
|
186
|
+
|
|
187
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
188
|
+
def test_wide_chart_legend_position(self, kind, element):
|
|
189
|
+
plot = self.df.hvplot(kind=kind, value_label='Test', group_label='Category', legend='left')
|
|
190
|
+
opts = Store.lookup_options('bokeh', plot, 'plot')
|
|
191
|
+
self.assertEqual(opts.kwargs['legend_position'], 'left')
|
|
192
|
+
|
|
193
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
194
|
+
def test_wide_chart_auto_group_label(self, kind, element):
|
|
195
|
+
self.df.columns.name = 'My Name'
|
|
196
|
+
self.assertEqual(self.df.hvplot().kdims, ['My Name'])
|
|
197
|
+
|
|
198
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
199
|
+
def test_tidy_chart(self, kind, element):
|
|
200
|
+
plot = self.df.hvplot(x='x', y='y', kind=kind)
|
|
201
|
+
self.assertEqual(plot, element(self.df, 'x', 'y'))
|
|
202
|
+
|
|
203
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
204
|
+
def test_tidy_chart_index(self, kind, element):
|
|
205
|
+
plot = self.df.hvplot(x='index', y='y', kind=kind)
|
|
206
|
+
self.assertEqual(plot, element(self.df, 'index', 'y'))
|
|
207
|
+
|
|
208
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
209
|
+
def test_tidy_chart_index_by(self, kind, element):
|
|
210
|
+
plot = self.df.hvplot(x='index', y='y', by='x', kind=kind)
|
|
211
|
+
obj = NdOverlay(
|
|
212
|
+
{
|
|
213
|
+
1: element(self.df[self.df.x == 1], 'index', 'y'),
|
|
214
|
+
3: element(self.df[self.df.x == 3], 'index', 'y'),
|
|
215
|
+
5: element(self.df[self.df.x == 5], 'index', 'y'),
|
|
216
|
+
},
|
|
217
|
+
'x',
|
|
218
|
+
)
|
|
219
|
+
self.assertEqual(plot, obj)
|
|
220
|
+
|
|
221
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
222
|
+
def test_tidy_chart_index_by_legend_position(self, kind, element):
|
|
223
|
+
plot = self.df.hvplot(x='index', y='y', by='x', kind=kind, legend='left')
|
|
224
|
+
opts = Store.lookup_options('bokeh', plot, 'plot')
|
|
225
|
+
self.assertEqual(opts.kwargs['legend_position'], 'left')
|
|
226
|
+
|
|
227
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
228
|
+
def test_use_index_disabled_uses_first_cols(self, kind, element):
|
|
229
|
+
plot = self.df.hvplot(use_index=False, kind=kind)
|
|
230
|
+
self.assertEqual(plot.kdims, ['x'])
|
|
231
|
+
self.assertEqual(plot.vdims, ['y'])
|
|
232
|
+
|
|
233
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
234
|
+
def test_tidy_chart_ranges(self, kind, element):
|
|
235
|
+
plot = self.df.hvplot(x='x', y='y', kind=kind, xlim=(0, 3), ylim=(5, 10))
|
|
236
|
+
opts = Store.lookup_options('bokeh', plot, 'plot').options
|
|
237
|
+
self.assertEqual(opts['xlim'], (0, 3))
|
|
238
|
+
self.assertEqual(opts['ylim'], (5, 10))
|
|
239
|
+
|
|
240
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
241
|
+
def test_wide_chart_ranges(self, kind, element):
|
|
242
|
+
plot = self.df.hvplot(kind=kind, xlim=(0, 3), ylim=(5, 10))
|
|
243
|
+
opts = Store.lookup_options('bokeh', plot.last, 'plot').options
|
|
244
|
+
self.assertEqual(opts['xlim'], (0, 3))
|
|
245
|
+
self.assertEqual(opts['ylim'], (5, 10))
|
|
246
|
+
|
|
247
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
248
|
+
def test_tidy_chart_with_hover_cols(self, kind, element):
|
|
249
|
+
plot = self.cat_df.hvplot(x='x', y='y', kind=kind, hover_cols=['category'])
|
|
250
|
+
self.assertEqual(plot, element(self.cat_df, 'x', ['y', 'category']))
|
|
251
|
+
|
|
252
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
253
|
+
def test_tidy_chart_with_index_in_hover_cols(self, kind, element):
|
|
254
|
+
plot = self.df.hvplot(x='x', y='y', kind=kind, hover_cols=['index'])
|
|
255
|
+
altered_df = self.df.reset_index()
|
|
256
|
+
self.assertEqual(plot, element(altered_df, 'x', ['y', 'index']))
|
|
257
|
+
|
|
258
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
259
|
+
def test_tidy_chart_with_hover_cols_as_all(self, kind, element):
|
|
260
|
+
plot = self.cat_df.hvplot(x='x', y='y', kind=kind, hover_cols='all')
|
|
261
|
+
altered_df = self.cat_df.reset_index()
|
|
262
|
+
self.assertEqual(plot, element(altered_df, 'x', ['y', 'index', 'category']))
|
|
263
|
+
|
|
264
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
265
|
+
def test_tidy_chart_with_hover_cols_as_all_with_use_index_as_false(self, kind, element):
|
|
266
|
+
plot = self.cat_df.hvplot(x='x', y='y', kind=kind, hover_cols='all', use_index=False)
|
|
267
|
+
self.assertEqual(plot, element(self.cat_df, 'x', ['y', 'category']))
|
|
268
|
+
|
|
269
|
+
def test_area_stacked(self):
|
|
270
|
+
plot = self.df.hvplot.area(stacked=True)
|
|
271
|
+
obj = NdOverlay(
|
|
272
|
+
{
|
|
273
|
+
'x': Area(self.df, 'index', 'x').redim(x='value'),
|
|
274
|
+
'y': Area(self.df, 'index', 'y').redim(y='value'),
|
|
275
|
+
},
|
|
276
|
+
'Variable',
|
|
277
|
+
)
|
|
278
|
+
self.assertEqual(plot, Area.stack(obj))
|
|
279
|
+
|
|
280
|
+
def test_scatter_color_set_to_series(self):
|
|
281
|
+
if is_dask(self.df['y']):
|
|
282
|
+
y = self.df['y'].compute()
|
|
283
|
+
else:
|
|
284
|
+
y = self.df['y']
|
|
285
|
+
actual = self.df.hvplot.scatter('x', 'y', c=y)
|
|
286
|
+
altered_df = self.df.assign(_color=y)
|
|
287
|
+
expected = altered_df.hvplot.scatter('x', 'y', c='_color')
|
|
288
|
+
self.assertEqual(actual, expected)
|
|
289
|
+
|
|
290
|
+
def test_scatter_size_set_to_series(self):
|
|
291
|
+
if is_dask(self.df['y']):
|
|
292
|
+
y = self.df['y'].compute()
|
|
293
|
+
else:
|
|
294
|
+
y = self.df['y']
|
|
295
|
+
plot = self.df.hvplot.scatter('x', 'y', s=y)
|
|
296
|
+
opts = Store.lookup_options('bokeh', plot, 'style')
|
|
297
|
+
assert '_size' in plot.data.columns
|
|
298
|
+
self.assertEqual(opts.kwargs['size'], '_size')
|
|
299
|
+
|
|
300
|
+
def test_scatter_color_by_legend_position(self):
|
|
301
|
+
plot = self.cat_df.hvplot.scatter('x', 'y', c='category', legend='left')
|
|
302
|
+
opts = Store.lookup_options('bokeh', plot, 'plot')
|
|
303
|
+
self.assertEqual(opts.kwargs['legend_position'], 'left')
|
|
304
|
+
|
|
305
|
+
def test_histogram_by_category_legend_position(self):
|
|
306
|
+
plot = self.cat_df.hvplot.hist('y', by='category', legend='left')
|
|
307
|
+
opts = Store.lookup_options('bokeh', plot, 'plot')
|
|
308
|
+
self.assertEqual(opts.kwargs['legend_position'], 'left')
|
|
309
|
+
|
|
310
|
+
def test_histogram_wide_set_group_label(self):
|
|
311
|
+
plot = self.df.hvplot.hist(group_label='Test')
|
|
312
|
+
assert plot.kdims[0].name == 'Test'
|
|
313
|
+
|
|
314
|
+
def test_scatter_color_internally_set_to_dim(self):
|
|
315
|
+
altered_df = self.cat_df.copy().rename(columns={'category': 'red'})
|
|
316
|
+
plot = altered_df.hvplot.scatter('x', 'y', c='red')
|
|
317
|
+
opts = Store.lookup_options('bokeh', plot, 'style')
|
|
318
|
+
self.assertIsInstance(opts.kwargs['color'], dim)
|
|
319
|
+
self.assertEqual(opts.kwargs['color'].dimension.name, 'red')
|
|
320
|
+
|
|
321
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
322
|
+
def test_only_includes_num_chart(self, kind, element):
|
|
323
|
+
plot = self.cat_df.hvplot(kind=kind)
|
|
324
|
+
obj = NdOverlay(
|
|
325
|
+
{
|
|
326
|
+
'x': element(self.cat_df, 'index', 'x').redim(x='value'),
|
|
327
|
+
'y': element(self.cat_df, 'index', 'y').redim(y='value'),
|
|
328
|
+
},
|
|
329
|
+
'Variable',
|
|
330
|
+
)
|
|
331
|
+
self.assertEqual(plot, obj)
|
|
332
|
+
|
|
333
|
+
@parameterized.expand([('line', Curve), ('area', Area), ('scatter', Scatter)])
|
|
334
|
+
def test_includes_str_if_no_num_chart(self, kind, element):
|
|
335
|
+
plot = self.cat_only_df.hvplot(kind=kind)
|
|
336
|
+
obj = NdOverlay(
|
|
337
|
+
{
|
|
338
|
+
'upper': element(self.cat_only_df, 'index', 'upper').redim(upper='value'),
|
|
339
|
+
'lower': element(self.cat_only_df, 'index', 'lower').redim(lower='value'),
|
|
340
|
+
},
|
|
341
|
+
'Variable',
|
|
342
|
+
)
|
|
343
|
+
self.assertEqual(plot, obj)
|
|
344
|
+
|
|
345
|
+
def test_time_df_sorts_on_plot(self):
|
|
346
|
+
scrambled = self.time_df.sample(frac=1)
|
|
347
|
+
plot = scrambled.hvplot(x='time')
|
|
348
|
+
assert (plot.data == self.time_df).all().all()
|
|
349
|
+
assert len(plot.data.time.unique()) == len(plot.data.time)
|
|
350
|
+
|
|
351
|
+
def test_time_df_does_not_sort_on_plot_if_sort_date_off(self):
|
|
352
|
+
scrambled = self.time_df.sample(frac=1)
|
|
353
|
+
plot = scrambled.hvplot(x='time', sort_date=False)
|
|
354
|
+
assert (plot.data == scrambled).all().all()
|
|
355
|
+
assert len(plot.data.time.unique()) == len(plot.data.time)
|
|
356
|
+
|
|
357
|
+
def test_time_df_sorts_on_plot_using_index_as_x(self):
|
|
358
|
+
df = self.time_df.set_index('time')
|
|
359
|
+
scrambled = df.sample(frac=1)
|
|
360
|
+
plot = scrambled.hvplot()
|
|
361
|
+
# HoloViews 1.18 uses reset_index and 1.19 does not.
|
|
362
|
+
time = plot.data.time if 'time' in plot.data.columns else plot.data.index
|
|
363
|
+
assert (time == df.index).all()
|
|
364
|
+
assert len(time.unique()) == len(time)
|
|
365
|
+
|
|
366
|
+
def test_time_df_does_not_sort_on_plot_if_sort_date_off_using_index_as_x(self):
|
|
367
|
+
df = self.time_df.set_index('time')
|
|
368
|
+
scrambled = df.sample(frac=1)
|
|
369
|
+
plot = scrambled.hvplot(sort_date=False)
|
|
370
|
+
# HoloViews 1.18 uses reset_index and 1.19 does not.
|
|
371
|
+
time = plot.data.time if 'time' in plot.data.columns else plot.data.index
|
|
372
|
+
assert (time == scrambled.index).all().all()
|
|
373
|
+
assert len(time.unique()) == len(time)
|
|
374
|
+
|
|
375
|
+
def test_time_df_with_groupby_as_derived_datetime(self):
|
|
376
|
+
plot = self.time_df.hvplot(groupby='time.dayofweek', dynamic=False)
|
|
377
|
+
assert list(plot.keys()) == [0, 1, 2, 3, 4, 5, 6]
|
|
378
|
+
assert list(plot.dimensions()) == ['time.dayofweek', 'index', 'A']
|
|
379
|
+
|
|
380
|
+
def test_time_df_with_by_as_derived_datetime(self):
|
|
381
|
+
plot = self.time_df.hvplot(by='time.month', dynamic=False)
|
|
382
|
+
assert list(plot.keys()) == [1]
|
|
383
|
+
assert list(plot.dimensions()) == ['time.month', 'index', 'A']
|
|
384
|
+
|
|
385
|
+
def test_time_df_with_x_as_derived_datetime(self):
|
|
386
|
+
plot = self.time_df.hvplot.scatter(x='time.day', dynamic=False)
|
|
387
|
+
assert list(plot.dimensions()) == ['time.day', 'A']
|
|
388
|
+
|
|
389
|
+
def test_time_df_as_index_with_x_as_derived_datetime_using_name(self):
|
|
390
|
+
indexed = self.time_df.set_index('time')
|
|
391
|
+
plot = indexed.hvplot.scatter(x='time.day', dynamic=False)
|
|
392
|
+
assert list(plot.dimensions()) == ['time.day', 'A']
|
|
393
|
+
|
|
394
|
+
def test_time_df_as_index_with_x_as_derived_datetime_using_index(self):
|
|
395
|
+
indexed = self.time_df.set_index('time')
|
|
396
|
+
plot = indexed.hvplot.scatter(x='index.day', dynamic=False)
|
|
397
|
+
assert list(plot.dimensions()) == ['index.day', 'A']
|
|
398
|
+
|
|
399
|
+
def test_default_y_not_in_by(self):
|
|
400
|
+
plot = self.cat_df.hvplot.scatter(by='x')
|
|
401
|
+
assert plot.kdims == ['x']
|
|
402
|
+
assert plot[1].kdims == ['index']
|
|
403
|
+
assert plot[1].vdims == ['y']
|
|
404
|
+
|
|
405
|
+
def test_errorbars_no_hover(self):
|
|
406
|
+
plot = self.df_desc.hvplot.errorbars(y='mean', yerr1='std')
|
|
407
|
+
assert list(plot.dimensions()) == ['index', 'mean', 'std']
|
|
408
|
+
bkplot = Store.renderers['bokeh'].get_plot(plot)
|
|
409
|
+
assert not bkplot.tools
|
|
410
|
+
|
|
411
|
+
def test_labels_format(self):
|
|
412
|
+
plot = self.df.hvplot('x', 'y', text='({x}, {y})', kind='labels')
|
|
413
|
+
assert list(plot.dimensions()) == [Dimension('x'), Dimension('y'), Dimension('label')]
|
|
414
|
+
assert list(plot.data['label']) == ['(1, 2)', '(3, 4)', '(5, 6)']
|
|
415
|
+
|
|
416
|
+
def test_labels_no_format_edge_case(self):
|
|
417
|
+
plot = self.edge_df.hvplot.labels('Longitude', 'Latitude')
|
|
418
|
+
assert list(plot.dimensions()) == [
|
|
419
|
+
Dimension('Longitude'),
|
|
420
|
+
Dimension('Latitude'),
|
|
421
|
+
Dimension('Volume {m3}'),
|
|
422
|
+
]
|
|
423
|
+
assert list(plot.data['Volume {m3}']) == ['1', '2', '3']
|
|
424
|
+
|
|
425
|
+
def test_labels_format_float(self):
|
|
426
|
+
plot = self.edge_df.hvplot.labels(
|
|
427
|
+
'Longitude', 'Latitude', text='{Longitude:.1f}E {Latitude:.2f}N'
|
|
428
|
+
)
|
|
429
|
+
assert list(plot.dimensions()) == [
|
|
430
|
+
Dimension('Longitude'),
|
|
431
|
+
Dimension('Latitude'),
|
|
432
|
+
Dimension('label'),
|
|
433
|
+
]
|
|
434
|
+
assert list(plot.data['label']) == ['-58.7E -34.58N', '-47.9E -15.78N', '-70.7E -33.45N']
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
class TestChart1DDask(TestChart1D):
|
|
438
|
+
def setUp(self):
|
|
439
|
+
super().setUp()
|
|
440
|
+
try:
|
|
441
|
+
import dask.dataframe as dd
|
|
442
|
+
except ImportError:
|
|
443
|
+
raise SkipTest('Dask not available')
|
|
444
|
+
import hvplot.dask # noqa
|
|
445
|
+
|
|
446
|
+
self.df = dd.from_pandas(self.df, npartitions=2)
|
|
447
|
+
self.dt_df = dd.from_pandas(self.dt_df, npartitions=3)
|
|
448
|
+
self.cat_df = dd.from_pandas(self.cat_df, npartitions=3)
|
|
449
|
+
self.cat_only_df = dd.from_pandas(self.cat_only_df, npartitions=1)
|
|
450
|
+
|
|
451
|
+
def test_by_datetime_accessor(self):
|
|
452
|
+
raise SkipTest("Can't expand dt accessor columns when using dask")
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Fugue test suite"""
|
|
2
|
+
|
|
3
|
+
import hvplot
|
|
4
|
+
import pandas as pd
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
# Patch required before importing hvplot.fugue
|
|
8
|
+
hvplot.util._fugue_ipython = True
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
import fugue.api as fa
|
|
12
|
+
import hvplot.fugue # noqa: F401
|
|
13
|
+
except ImportError:
|
|
14
|
+
pytest.skip(allow_module_level=True)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@pytest.fixture
|
|
18
|
+
def table():
|
|
19
|
+
df = pd.DataFrame(
|
|
20
|
+
{
|
|
21
|
+
'g': ['a', 'b', 'a', 'b', 'a', 'b'],
|
|
22
|
+
'x': [1, 2, 3, 4, 5, 6],
|
|
23
|
+
'y': [1, 2, 3, 4, 5, 6],
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
return df
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_fugure_ipython_line(table, capsys):
|
|
30
|
+
"""hvplot works with Fugue"""
|
|
31
|
+
fa.fugue_sql(
|
|
32
|
+
"""
|
|
33
|
+
OUTPUT table USING hvplot:line(
|
|
34
|
+
x="x",
|
|
35
|
+
y="y",
|
|
36
|
+
by="g",
|
|
37
|
+
size=100,
|
|
38
|
+
opts={"width": 500, "height": 500}
|
|
39
|
+
)
|
|
40
|
+
"""
|
|
41
|
+
)
|
|
42
|
+
# Check that the output contains the following:
|
|
43
|
+
# Column
|
|
44
|
+
# [0] HoloViews(NdOverlay)
|
|
45
|
+
output = capsys.readouterr().out
|
|
46
|
+
assert output == 'Column\n [0] HoloViews(NdOverlay)\n'
|