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.
Files changed (63) hide show
  1. hvplot/__init__.py +322 -0
  2. hvplot/_version.py +16 -0
  3. hvplot/backend_transforms.py +329 -0
  4. hvplot/converter.py +2855 -0
  5. hvplot/cudf.py +26 -0
  6. hvplot/dask.py +42 -0
  7. hvplot/data/crime.csv +56 -0
  8. hvplot/datasets.yaml +48 -0
  9. hvplot/fugue.py +64 -0
  10. hvplot/ibis.py +21 -0
  11. hvplot/intake.py +32 -0
  12. hvplot/interactive.py +968 -0
  13. hvplot/networkx.py +625 -0
  14. hvplot/pandas.py +30 -0
  15. hvplot/plotting/__init__.py +63 -0
  16. hvplot/plotting/andrews_curves.py +99 -0
  17. hvplot/plotting/core.py +2288 -0
  18. hvplot/plotting/lag_plot.py +34 -0
  19. hvplot/plotting/parallel_coordinates.py +85 -0
  20. hvplot/plotting/scatter_matrix.py +220 -0
  21. hvplot/polars.py +21 -0
  22. hvplot/sample_data.py +30 -0
  23. hvplot/streamz.py +21 -0
  24. hvplot/tests/__init__.py +0 -0
  25. hvplot/tests/conftest.py +44 -0
  26. hvplot/tests/data/README.md +5 -0
  27. hvplot/tests/data/RGB-red.byte.tif +0 -0
  28. hvplot/tests/plotting/__init__.py +0 -0
  29. hvplot/tests/plotting/testcore.py +108 -0
  30. hvplot/tests/plotting/testohlc.py +34 -0
  31. hvplot/tests/plotting/testscattermatrix.py +138 -0
  32. hvplot/tests/test_links.py +99 -0
  33. hvplot/tests/testbackend_transforms.py +89 -0
  34. hvplot/tests/testcharts.py +452 -0
  35. hvplot/tests/testfugue.py +46 -0
  36. hvplot/tests/testgeo.py +468 -0
  37. hvplot/tests/testgeowithoutgv.py +60 -0
  38. hvplot/tests/testgridplots.py +259 -0
  39. hvplot/tests/testhelp.py +75 -0
  40. hvplot/tests/testibis.py +17 -0
  41. hvplot/tests/testinteractive.py +1442 -0
  42. hvplot/tests/testnetworkx.py +26 -0
  43. hvplot/tests/testoperations.py +385 -0
  44. hvplot/tests/testoptions.py +596 -0
  45. hvplot/tests/testoverrides.py +74 -0
  46. hvplot/tests/testpanel.py +70 -0
  47. hvplot/tests/testpatch.py +135 -0
  48. hvplot/tests/testplotting.py +69 -0
  49. hvplot/tests/teststreaming.py +28 -0
  50. hvplot/tests/testtransforms.py +39 -0
  51. hvplot/tests/testui.py +383 -0
  52. hvplot/tests/testutil.py +378 -0
  53. hvplot/tests/util.py +82 -0
  54. hvplot/ui.py +1032 -0
  55. hvplot/util.py +677 -0
  56. hvplot/utilities.py +129 -0
  57. hvplot/xarray.py +62 -0
  58. hvplot-0.9.3a1.dist-info/LICENSE +29 -0
  59. hvplot-0.9.3a1.dist-info/METADATA +243 -0
  60. hvplot-0.9.3a1.dist-info/RECORD +63 -0
  61. hvplot-0.9.3a1.dist-info/WHEEL +5 -0
  62. hvplot-0.9.3a1.dist-info/entry_points.txt +2 -0
  63. hvplot-0.9.3a1.dist-info/top_level.txt +1 -0
hvplot/tests/testui.py ADDED
@@ -0,0 +1,383 @@
1
+ import re
2
+ from textwrap import dedent
3
+
4
+ import holoviews as hv
5
+ import pandas as pd
6
+ import hvplot.pandas
7
+ import hvplot.xarray
8
+ import xarray as xr
9
+
10
+ import pytest
11
+
12
+ from bokeh.sampledata import penguins
13
+ from hvplot.ui import hvDataFrameExplorer, hvGridExplorer
14
+
15
+ df = penguins.data
16
+ ds_air_temperature = xr.tutorial.open_dataset('air_temperature')
17
+
18
+
19
+ def test_explorer_basic():
20
+ explorer = hvplot.explorer(df)
21
+
22
+ assert isinstance(explorer, hvDataFrameExplorer)
23
+ assert explorer.kind == 'scatter'
24
+ assert explorer.x == 'index'
25
+ assert explorer.y == 'species'
26
+
27
+
28
+ def test_explorer_settings():
29
+ explorer = hvplot.explorer(df)
30
+
31
+ explorer.param.update(
32
+ kind='scatter',
33
+ x='bill_length_mm',
34
+ y_multi=['bill_depth_mm'],
35
+ by=['species'],
36
+ )
37
+
38
+ settings = explorer.settings()
39
+
40
+ assert settings == dict(
41
+ by=['species'],
42
+ kind='scatter',
43
+ x='bill_length_mm',
44
+ y=['bill_depth_mm'],
45
+ )
46
+
47
+
48
+ def test_explorer_plot_code():
49
+ explorer = hvplot.explorer(df)
50
+
51
+ explorer.param.update(
52
+ kind='scatter',
53
+ x='bill_length_mm',
54
+ y_multi=['bill_depth_mm'],
55
+ by=['species'],
56
+ )
57
+
58
+ hvplot_code = explorer.plot_code()
59
+
60
+ assert hvplot_code == (
61
+ 'df.hvplot(\n'
62
+ " by=['species'],\n"
63
+ " kind='scatter',\n"
64
+ " x='bill_length_mm',\n"
65
+ " y=['bill_depth_mm'],\n"
66
+ " legend='bottom_right',\n"
67
+ " widget_location='bottom',\n"
68
+ ')'
69
+ )
70
+
71
+ hvplot_code = explorer.plot_code(var_name='othername')
72
+
73
+ assert hvplot_code == (
74
+ 'othername.hvplot(\n'
75
+ " by=['species'],\n"
76
+ " kind='scatter',\n"
77
+ " x='bill_length_mm',\n"
78
+ " y=['bill_depth_mm'],\n"
79
+ " legend='bottom_right',\n"
80
+ " widget_location='bottom',\n"
81
+ ')'
82
+ )
83
+
84
+
85
+ def test_explorer_hvplot():
86
+ explorer = hvplot.explorer(df)
87
+
88
+ explorer.param.update(
89
+ kind='scatter',
90
+ x='bill_length_mm',
91
+ y_multi=['bill_depth_mm'],
92
+ )
93
+
94
+ plot = explorer.hvplot()
95
+
96
+ assert isinstance(plot, hv.Scatter)
97
+ assert plot.kdims[0].name == 'bill_length_mm'
98
+ assert plot.vdims[0].name == 'bill_depth_mm'
99
+
100
+
101
+ def test_explorer_save(tmp_path):
102
+ explorer = hvplot.explorer(df)
103
+
104
+ explorer.param.update(
105
+ kind='scatter',
106
+ x='bill_length_mm',
107
+ y_multi=['bill_depth_mm'],
108
+ )
109
+
110
+ outfile = tmp_path / 'plot.html'
111
+
112
+ explorer.save(outfile)
113
+
114
+ assert outfile.exists()
115
+
116
+
117
+ def test_explorer_kwargs_controls():
118
+ explorer = hvplot.explorer(df, title='Dummy title', width=200)
119
+
120
+ assert explorer.labels.title == 'Dummy title'
121
+ assert explorer.axes.width == 200
122
+
123
+
124
+ def test_explorer_kwargs_controls_error_not_supported():
125
+ with pytest.raises(
126
+ TypeError,
127
+ match=re.escape(
128
+ "__init__() got keyword(s) not supported by any control: {'not_a_control_kwarg': None}"
129
+ ),
130
+ ):
131
+ hvplot.explorer(df, title='Dummy title', not_a_control_kwarg=None)
132
+
133
+
134
+ def test_explorer_hvplot_gridded_basic():
135
+ explorer = hvplot.explorer(ds_air_temperature)
136
+
137
+ assert isinstance(explorer, hvGridExplorer)
138
+ assert isinstance(explorer._data, xr.DataArray)
139
+ assert explorer.kind == 'image'
140
+ assert explorer.x == 'lat'
141
+ assert explorer.y == 'lon'
142
+ assert explorer.by == []
143
+ assert explorer.groupby == ['time']
144
+
145
+
146
+ def test_explorer_hvplot_gridded_2d():
147
+ ds = ds_air_temperature.isel(time=0)
148
+ explorer = hvplot.explorer(ds)
149
+
150
+ assert isinstance(explorer, hvGridExplorer)
151
+ assert isinstance(explorer._data, xr.DataArray)
152
+ assert explorer.kind == 'image'
153
+ assert explorer.x == 'lat'
154
+ assert explorer.y == 'lon'
155
+ assert explorer.by == []
156
+ assert explorer.groupby == []
157
+
158
+
159
+ def test_explorer_hvplot_gridded_two_variables():
160
+ ds = ds_air_temperature.copy()
161
+ ds['airx2'] = ds['air'] * 2
162
+ explorer = hvplot.explorer(ds)
163
+
164
+ assert isinstance(explorer, hvGridExplorer)
165
+ assert isinstance(explorer._data, xr.DataArray)
166
+ assert list(explorer._data['variable']) == ['air', 'airx2']
167
+ assert explorer.kind == 'image'
168
+ assert explorer.x == 'lat'
169
+ assert explorer.y == 'lon'
170
+ assert explorer.by == []
171
+ assert explorer.groupby == ['time', 'variable']
172
+
173
+
174
+ def test_explorer_hvplot_gridded_dataarray():
175
+ da = ds_air_temperature['air']
176
+ explorer = hvplot.explorer(da)
177
+
178
+ assert isinstance(explorer, hvGridExplorer)
179
+ assert isinstance(explorer._data, xr.DataArray)
180
+ assert explorer.kind == 'image'
181
+ assert explorer.x == 'lat'
182
+ assert explorer.y == 'lon'
183
+ assert explorer.by == []
184
+ assert explorer.groupby == ['time']
185
+
186
+
187
+ def test_explorer_hvplot_gridded_options():
188
+ explorer = hvplot.explorer(ds_air_temperature)
189
+ assert explorer._controls[0].groups.keys() == {'dataframe', 'gridded', 'geom'}
190
+
191
+
192
+ def test_explorer_hvplot_geo():
193
+ pytest.importorskip('geoviews')
194
+ df = pd.DataFrame({'x': [-9796115.18980811], 'y': [4838471.398061159]})
195
+ explorer = hvplot.explorer(df, x='x', geo=True, kind='points')
196
+ assert explorer.geographic.geo
197
+ assert explorer.geographic.global_extent
198
+ assert explorer.geographic.features == ['coastline']
199
+ assert explorer.geographic.crs == 'GOOGLE_MERCATOR'
200
+ assert explorer.geographic.projection == 'GOOGLE_MERCATOR'
201
+
202
+
203
+ def test_explorer_live_update_init():
204
+ explorer = hvplot.explorer(df)
205
+ assert explorer.statusbar.live_update is True
206
+
207
+ explorer = hvplot.explorer(df, live_update=False)
208
+ assert explorer._hv_pane.object is None
209
+ assert 'live_update' not in explorer.settings()
210
+
211
+
212
+ def test_explorer_live_update_after_init():
213
+ explorer = hvplot.explorer(df)
214
+ assert explorer._hv_pane.object.type is hv.Scatter
215
+ explorer.kind = 'line'
216
+ assert explorer._hv_pane.object.type is hv.Curve
217
+
218
+ explorer.statusbar.live_update = False
219
+ explorer.kind = 'scatter'
220
+ assert explorer._hv_pane.object.type is hv.Curve
221
+ assert 'scatter' not in explorer.code
222
+
223
+ explorer.statusbar.live_update = True
224
+ assert explorer._hv_pane.object.type is hv.Scatter
225
+ assert 'scatter' in explorer.code
226
+
227
+
228
+ def test_explorer_method_dataframe():
229
+ explorer = df.hvplot.explorer()
230
+
231
+ assert isinstance(explorer, hvDataFrameExplorer)
232
+ assert explorer.kind == 'scatter'
233
+ assert explorer.x == 'index'
234
+ assert explorer.y == 'species'
235
+
236
+
237
+ def test_explorer_method_grid():
238
+ explorer = ds_air_temperature.hvplot.explorer()
239
+
240
+ assert isinstance(explorer, hvGridExplorer)
241
+ assert explorer.kind == 'image'
242
+ assert explorer.x == 'lat'
243
+ assert explorer.y == 'lon'
244
+
245
+
246
+ def test_explorer_method_kind():
247
+ explorer = df.hvplot.explorer(kind='scatter')
248
+
249
+ assert isinstance(explorer, hvDataFrameExplorer)
250
+ assert explorer.kind == 'scatter'
251
+ assert explorer.x == 'index'
252
+ assert explorer.y == 'species'
253
+
254
+
255
+ def test_explorer_method_as_kind():
256
+ explorer = df.hvplot(kind='explorer')
257
+
258
+ assert isinstance(explorer, hvDataFrameExplorer)
259
+ assert explorer.kind == 'scatter'
260
+ assert explorer.x == 'index'
261
+ assert explorer.y == 'species'
262
+
263
+
264
+ def test_explorer_method_propagates_kwargs():
265
+ explorer = df.hvplot.explorer(title='Dummy title', x='bill_length_mm')
266
+
267
+ assert isinstance(explorer, hvDataFrameExplorer)
268
+ assert explorer.kind == 'scatter'
269
+ assert explorer.x == 'bill_length_mm'
270
+ assert explorer.y == 'species'
271
+ assert explorer.labels.title == 'Dummy title'
272
+
273
+
274
+ def test_explorer_code_dataframe():
275
+ explorer = hvplot.explorer(df, x='bill_length_mm', kind='points')
276
+ assert explorer.code == dedent("""\
277
+ df.hvplot(
278
+ kind='points',
279
+ x='bill_length_mm',
280
+ y='species',
281
+ legend='bottom_right',
282
+ widget_location='bottom',
283
+ )""")
284
+ assert explorer._code_pane.object == dedent("""\
285
+ ```python
286
+ df.hvplot(
287
+ kind='points',
288
+ x='bill_length_mm',
289
+ y='species',
290
+ legend='bottom_right',
291
+ widget_location='bottom',
292
+ )
293
+ ```""")
294
+
295
+
296
+ def test_explorer_code_gridded():
297
+ explorer = hvplot.explorer(ds_air_temperature, x='lon', y='lat', kind='image')
298
+ code = explorer.code
299
+ assert code == dedent("""\
300
+ ds['air'].hvplot(
301
+ colorbar=True,
302
+ groupby=['time'],
303
+ kind='image',
304
+ x='lon',
305
+ y='lat',
306
+ legend='bottom_right',
307
+ widget_location='bottom',
308
+ )""")
309
+
310
+ assert explorer._code_pane.object == dedent("""\
311
+ ```python
312
+ ds['air'].hvplot(
313
+ colorbar=True,
314
+ groupby=['time'],
315
+ kind='image',
316
+ x='lon',
317
+ y='lat',
318
+ legend='bottom_right',
319
+ widget_location='bottom',
320
+ )
321
+ ```""")
322
+
323
+
324
+ def test_explorer_code_gridded_dataarray():
325
+ da = ds_air_temperature['air']
326
+ explorer = hvplot.explorer(da, x='lon', y='lat', kind='image')
327
+ code = explorer.code
328
+ assert code == dedent("""\
329
+ da.hvplot(
330
+ colorbar=True,
331
+ groupby=['time'],
332
+ kind='image',
333
+ x='lon',
334
+ y='lat',
335
+ legend='bottom_right',
336
+ widget_location='bottom',
337
+ )""")
338
+
339
+ assert explorer._code_pane.object == dedent("""\
340
+ ```python
341
+ da.hvplot(
342
+ colorbar=True,
343
+ groupby=['time'],
344
+ kind='image',
345
+ x='lon',
346
+ y='lat',
347
+ legend='bottom_right',
348
+ widget_location='bottom',
349
+ )
350
+ ```""")
351
+
352
+
353
+ def test_explorer_code_opts():
354
+ da = ds_air_temperature['air']
355
+ explorer = hvplot.explorer(da, x='lon', y='lat', kind='image', opts={'color_levels': 3})
356
+ code = explorer.code
357
+ assert code == dedent("""\
358
+ da.hvplot(
359
+ colorbar=True,
360
+ groupby=['time'],
361
+ kind='image',
362
+ x='lon',
363
+ y='lat',
364
+ legend='bottom_right',
365
+ widget_location='bottom',
366
+ ).opts(
367
+ color_levels=3,
368
+ )""")
369
+
370
+ assert explorer._code_pane.object == dedent("""\
371
+ ```python
372
+ da.hvplot(
373
+ colorbar=True,
374
+ groupby=['time'],
375
+ kind='image',
376
+ x='lon',
377
+ y='lat',
378
+ legend='bottom_right',
379
+ widget_location='bottom',
380
+ ).opts(
381
+ color_levels=3,
382
+ )
383
+ ```""")