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
@@ -0,0 +1,259 @@
1
+ import os
2
+ import tempfile
3
+
4
+ from unittest import SkipTest
5
+ from collections import OrderedDict
6
+
7
+ import numpy as np
8
+ from holoviews import Store
9
+ from holoviews.element import RGB, Image
10
+ from holoviews.element.comparison import ComparisonTestCase
11
+
12
+ try:
13
+ import xarray as xr
14
+ except ImportError:
15
+ raise SkipTest('XArray not available')
16
+ else:
17
+ import hvplot.xarray # noqa
18
+
19
+
20
+ class TestGridPlots(ComparisonTestCase):
21
+ def setUp(self):
22
+ coords = OrderedDict([('band', [1, 2, 3]), ('y', [0, 1]), ('x', [0, 1])])
23
+ self.da_rgb = xr.DataArray(np.arange(12).reshape((3, 2, 2)), coords, ['band', 'y', 'x'])
24
+ coords = OrderedDict([('time', [0, 1]), ('band', [1, 2, 3]), ('y', [0, 1]), ('x', [0, 1])])
25
+ self.da_rgb_by_time = xr.DataArray(
26
+ np.arange(24).reshape((2, 3, 2, 2)), coords, ['time', 'band', 'y', 'x']
27
+ )
28
+
29
+ coords = OrderedDict([('time', [0, 1]), ('lat', [0, 1]), ('lon', [0, 1])])
30
+ self.da_img_by_time = xr.DataArray(
31
+ np.arange(8).reshape((2, 2, 2)), coords, ['time', 'lat', 'lon']
32
+ ).assign_coords(lat1=xr.DataArray([2, 3], dims=['lat']))
33
+
34
+ self.xarr_with_attrs = xr.DataArray(
35
+ np.random.rand(10, 10),
36
+ coords=[('x', range(10)), ('y', range(10))],
37
+ dims=['y', 'x'],
38
+ attrs={'long_name': 'luminosity', 'units': 'lm'},
39
+ )
40
+ self.xarr_with_attrs.x.attrs['long_name'] = 'Declination'
41
+ self.xarr_with_attrs.y.attrs['long_name'] = 'Right Ascension'
42
+
43
+ self.xds_with_attrs = xr.Dataset({'light': self.xarr_with_attrs})
44
+ self.da_img = xr.DataArray(np.arange(-2, 2).reshape((2, 2)), name='foo')
45
+ self.big_img = xr.DataArray(np.arange(-1e6, 1e6).reshape(1000, 2000))
46
+
47
+ self.ds = xr.Dataset(
48
+ {
49
+ 'temp': (('lon', 'lat'), 15 + 8 * np.random.randn(2, 2)),
50
+ 'precip': (('lon', 'lat'), 10 * np.random.rand(2, 2)),
51
+ },
52
+ coords={'lon': [-99.83, -99.32], 'lat': [42.25, 42.21]},
53
+ )
54
+
55
+ xs = np.linspace(0, 10, 5)
56
+ lon = xs * xs[np.newaxis, :].T
57
+ lat = xs + xs[:, np.newaxis]
58
+ coords = {
59
+ 'lon': (('ny', 'nx'), lon),
60
+ 'lat': (('ny', 'nx'), lat),
61
+ 'time': [1, 2, 3],
62
+ 'samples': ('nsamples', [0, 1, 2, 3]),
63
+ }
64
+ self.ds_unindexed = xr.DataArray(
65
+ np.random.rand(5, 5, 3, 4), coords=coords, dims=('nx', 'ny', 'time', 'nsamples')
66
+ )
67
+
68
+ def test_rgb_dataarray_no_args(self):
69
+ rgb = self.da_rgb.hvplot()
70
+ self.assertEqual(rgb, RGB(([0, 1], [0, 1]) + tuple(self.da_rgb.values)))
71
+
72
+ def test_rgb_dataarray_explicit_args(self):
73
+ rgb = self.da_rgb.hvplot('x', 'y')
74
+ self.assertEqual(rgb, RGB(([0, 1], [0, 1]) + tuple(self.da_rgb.values)))
75
+
76
+ def test_rgb_dataarray_explicit_args_and_kind(self):
77
+ rgb = self.da_rgb.hvplot.rgb('x', 'y')
78
+ self.assertEqual(rgb, RGB(([0, 1], [0, 1]) + tuple(self.da_rgb.values)))
79
+
80
+ def test_rgb_dataset(self):
81
+ rgb = self.da_rgb.to_dataset(name='z').hvplot.rgb()
82
+ self.assertEqual(rgb, RGB(([0, 1], [0, 1]) + tuple(self.da_rgb.values)))
83
+
84
+ def test_rgb_dataset_explicit_z(self):
85
+ rgb = self.da_rgb.to_dataset(name='z').hvplot.rgb(z='z')
86
+ self.assertEqual(rgb, RGB(([0, 1], [0, 1]) + tuple(self.da_rgb.values)))
87
+
88
+ def test_rgb_dataset_robust(self):
89
+ rgb = self.da_rgb.to_dataset(name='z').hvplot.rgb(robust=True)
90
+ self.assertNotEqual(rgb, RGB(([0, 1], [0, 1]) + tuple(self.da_rgb.values)))
91
+
92
+ def test_rgb_dataarray_groupby_explicit(self):
93
+ rgb = self.da_rgb_by_time.hvplot.rgb('x', 'y', groupby='time')
94
+ self.assertEqual(rgb[0], RGB(([0, 1], [0, 1]) + tuple(self.da_rgb_by_time.values[0])))
95
+ self.assertEqual(rgb[1], RGB(([0, 1], [0, 1]) + tuple(self.da_rgb_by_time.values[1])))
96
+
97
+ def test_rgb_dataarray_groupby_infer(self):
98
+ rgb = self.da_rgb_by_time.hvplot.rgb('x', 'y', bands='band')
99
+ self.assertEqual(rgb[0], RGB(([0, 1], [0, 1]) + tuple(self.da_rgb_by_time.values[0])))
100
+ self.assertEqual(rgb[1], RGB(([0, 1], [0, 1]) + tuple(self.da_rgb_by_time.values[1])))
101
+
102
+ def test_img_dataarray_infers_correct_other_dims(self):
103
+ img = self.da_img_by_time[0].hvplot()
104
+ self.assertEqual(img, Image(self.da_img_by_time[0], ['lon', 'lat'], ['value']))
105
+
106
+ def test_img_dataarray_robust_to_clim_percentile(self):
107
+ img = self.da_img_by_time[0].hvplot(robust=True)
108
+ assert img.opts['clim_percentile'] is True
109
+
110
+ def test_img_dataarray_groupby_infers_correct_other_dims(self):
111
+ img = self.da_img_by_time.hvplot(groupby='time')
112
+ self.assertEqual(img[0], Image(self.da_img_by_time[0], ['lon', 'lat'], ['value']))
113
+ self.assertEqual(img[1], Image(self.da_img_by_time[1], ['lon', 'lat'], ['value']))
114
+
115
+ def test_line_infer_dimension_params_from_xarray_attrs(self):
116
+ hmap = self.xarr_with_attrs.hvplot.line(groupby='x', dynamic=False)
117
+ self.assertEqual(hmap.kdims[0].label, 'Declination')
118
+ self.assertEqual(hmap.last.kdims[0].label, 'Right Ascension')
119
+ self.assertEqual(hmap.last.vdims[0].label, 'luminosity')
120
+ self.assertEqual(hmap.last.vdims[0].unit, 'lm')
121
+
122
+ def test_img_infer_dimension_params_from_xarray_attrs(self):
123
+ img = self.xarr_with_attrs.hvplot.image(clim=(0, 2))
124
+ self.assertEqual(img.kdims[0].label, 'Declination')
125
+ self.assertEqual(img.kdims[1].label, 'Right Ascension')
126
+ self.assertEqual(img.vdims[0].label, 'luminosity')
127
+ self.assertEqual(img.vdims[0].unit, 'lm')
128
+ self.assertEqual(img.vdims[0].range, (0, 2))
129
+
130
+ def test_table_infer_dimension_params_from_xarray_ds_attrs(self):
131
+ table = self.xds_with_attrs.hvplot.dataset()
132
+ self.assertEqual(table.kdims[0].label, 'Declination')
133
+ self.assertEqual(table.kdims[1].label, 'Right Ascension')
134
+ self.assertEqual(table.vdims[0].label, 'luminosity')
135
+ self.assertEqual(table.vdims[0].unit, 'lm')
136
+
137
+ def test_points_infer_dimension_params_from_xarray_attrs(self):
138
+ points = self.xarr_with_attrs.hvplot.points(c='value', clim=(0, 2))
139
+ self.assertEqual(points.kdims[0].label, 'Declination')
140
+ self.assertEqual(points.kdims[1].label, 'Right Ascension')
141
+ self.assertEqual(points.vdims[0].label, 'luminosity')
142
+ self.assertEqual(points.vdims[0].unit, 'lm')
143
+ self.assertEqual(points.vdims[0].range, (0, 2))
144
+
145
+ def test_dataset_infer_dimension_params_from_xarray_attrs(self):
146
+ ds = self.xarr_with_attrs.hvplot.dataset()
147
+ self.assertEqual(ds.kdims[0].label, 'Declination')
148
+ self.assertEqual(ds.kdims[1].label, 'Right Ascension')
149
+ self.assertEqual(ds.vdims[0].label, 'luminosity')
150
+ self.assertEqual(ds.vdims[0].unit, 'lm')
151
+
152
+ def test_table_infer_dimension_params_from_xarray_attrs(self):
153
+ table = self.xarr_with_attrs.hvplot.dataset()
154
+ self.assertEqual(table.kdims[0].label, 'Declination')
155
+ self.assertEqual(table.kdims[1].label, 'Right Ascension')
156
+ self.assertEqual(table.vdims[0].label, 'luminosity')
157
+ self.assertEqual(table.vdims[0].unit, 'lm')
158
+
159
+ def test_symmetric_img_deduces_symmetric(self):
160
+ plot = self.da_img.hvplot.image()
161
+ plot_opts = Store.lookup_options('bokeh', plot, 'plot')
162
+ self.assertEqual(plot_opts.kwargs.get('symmetric'), True)
163
+ style_opts = Store.lookup_options('bokeh', plot, 'style')
164
+ self.assertEqual(style_opts.kwargs['cmap'], 'coolwarm')
165
+
166
+ def test_symmetric_img_with_symmetric_set_to_false(self):
167
+ plot = self.da_img.hvplot.image(symmetric=False)
168
+ plot_opts = Store.lookup_options('bokeh', plot, 'plot')
169
+ self.assertEqual(plot_opts.kwargs.get('symmetric'), False)
170
+ style_opts = Store.lookup_options('bokeh', plot, 'style')
171
+ self.assertEqual(style_opts.kwargs['cmap'], 'kbc_r')
172
+
173
+ def test_symmetric_img_with_cmap_set(self):
174
+ plot = self.da_img.hvplot.image(cmap='fire')
175
+ plot_opts = Store.lookup_options('bokeh', plot, 'plot')
176
+ self.assertEqual(plot_opts.kwargs.get('symmetric'), True)
177
+ style_opts = Store.lookup_options('bokeh', plot, 'style')
178
+ self.assertEqual(style_opts.kwargs['cmap'], 'fire')
179
+
180
+ def test_symmetric_with_big_img_sets_symmetric_to_false_without_calculating(self):
181
+ plot = self.big_img.hvplot.image()
182
+ plot_opts = Store.lookup_options('bokeh', plot, 'plot')
183
+ self.assertEqual(plot_opts.kwargs.get('symmetric'), False)
184
+ style_opts = Store.lookup_options('bokeh', plot, 'style')
185
+ self.assertEqual(style_opts.kwargs['cmap'], 'kbc_r')
186
+
187
+ def test_symmetric_with_big_img_and_check_symmetric_max_calculates_symmetric(self):
188
+ plot = self.big_img.hvplot.image(check_symmetric_max=int(1e7))
189
+ plot_opts = Store.lookup_options('bokeh', plot, 'plot')
190
+ self.assertEqual(plot_opts.kwargs.get('symmetric'), True)
191
+ style_opts = Store.lookup_options('bokeh', plot, 'style')
192
+ self.assertEqual(style_opts.kwargs['cmap'], 'coolwarm')
193
+
194
+ def test_multiple_zs(self):
195
+ plot = self.ds.hvplot(x='lat', y='lon', z=['temp', 'precip'], dynamic=False)
196
+ assert 'temp' in plot.keys()
197
+ assert 'precip' in plot.keys()
198
+ assert plot['temp'].kdims == ['lat', 'lon']
199
+ assert plot['precip'].kdims == ['lat', 'lon']
200
+
201
+ def test_unindexed_quadmesh(self):
202
+ plot = self.ds_unindexed.hvplot.quadmesh(x='lon', y='lat')
203
+ assert len(plot.kdims) == 2
204
+ assert plot.kdims[0].name == 'time'
205
+ assert plot.kdims[1].name == 'nsamples'
206
+ p = plot[1, 0]
207
+ assert len(p.kdims) == 2
208
+ assert p.kdims[0].name == 'lon'
209
+ assert p.kdims[1].name == 'lat'
210
+
211
+ def test_symmetric_dataset_not_in_memory(self):
212
+ # Creating a netcdf file and loading it as to get an non in memory
213
+ # DataArray.
214
+ da = xr.DataArray(
215
+ data=np.arange(-100, 100).reshape(10, 10, 2),
216
+ dims=['x', 'y', 'z'],
217
+ coords={'x': np.arange(10), 'y': np.arange(10), 'z': np.arange(2)},
218
+ )
219
+ ds = xr.Dataset(data_vars={'value': da})
220
+ with tempfile.TemporaryDirectory() as tempdir:
221
+ fpath = os.path.join(tempdir, 'data.nc')
222
+ ds.to_netcdf(fpath)
223
+ ds = xr.open_dataset(fpath)
224
+ plot = ds.value.hvplot(x='x', y='y', check_symmetric_max=ds.value.size + 1)
225
+ plot[(0)]
226
+ plot_opts = Store.lookup_options('bokeh', plot.last, 'plot')
227
+ # If a DataArray is not in memory, computing whether it's symmetric should
228
+ # not be done and return False.
229
+ assert not plot_opts.kwargs['symmetric']
230
+ ds.close()
231
+
232
+ def test_symmetric_dataset_in_memory(self):
233
+ da = xr.DataArray(
234
+ data=np.arange(-100, 100).reshape(10, 10, 2),
235
+ dims=['x', 'y', 'z'],
236
+ coords={'x': np.arange(10), 'y': np.arange(10), 'z': np.arange(2)},
237
+ )
238
+ ds = xr.Dataset(data_vars={'value': da})
239
+ plot = ds.value.hvplot(x='x', y='y', check_symmetric_max=ds.value.size + 1)
240
+ plot[(0)]
241
+ plot_opts = Store.lookup_options('bokeh', plot.last, 'plot')
242
+ # This DataArray happens to be symmetric.
243
+ assert plot_opts.kwargs['symmetric']
244
+
245
+ def test_dataarray_unnamed_label(self):
246
+ plot = self.da_rgb.sel(band=1).hvplot.image(label='test')
247
+ assert plot.vdims[0].name == 'test'
248
+
249
+ def test_dataarray_unnamed_value_label(self):
250
+ plot = self.da_rgb.sel(band=1).hvplot.image(value_label='test')
251
+ assert plot.vdims[0].name == 'test'
252
+
253
+ def test_dataarray_label_precedence(self):
254
+ # name > label > value_label
255
+ plot = self.da_rgb.sel(band=1).rename('a').hvplot.image(label='b')
256
+ assert plot.vdims[0].name == 'a'
257
+
258
+ plot = self.da_rgb.sel(band=1).hvplot.image(label='b', value_label='c')
259
+ assert plot.vdims[0].name == 'b'
@@ -0,0 +1,75 @@
1
+ import hvplot.pandas
2
+ import pytest
3
+
4
+ from holoviews.core import Store
5
+ from holoviews.element import Curve
6
+
7
+
8
+ @pytest.fixture
9
+ def reset_default_backend():
10
+ yield
11
+ hvplot.extension('bokeh')
12
+ hvplot.extension.compatibility = None
13
+
14
+
15
+ def test_help_style_extension_output(reset_default_backend):
16
+ # default, after e.g. import hvplot.pandas
17
+ docstring, signature = hvplot._get_doc_and_signature(
18
+ cls=hvplot.hvPlot,
19
+ kind='line',
20
+ completions=False,
21
+ docstring=False,
22
+ generic=False,
23
+ style=True,
24
+ signature=None,
25
+ )
26
+ assert docstring == '\nStyle options\n-------------\n\n' + '\n'.join(
27
+ sorted(Store.registry['bokeh'][Curve].style_opts)
28
+ )
29
+
30
+ # The current backend becomes matplotlib
31
+ hvplot.extension('matplotlib', 'plotly')
32
+ docstring, signature = hvplot._get_doc_and_signature(
33
+ cls=hvplot.hvPlot,
34
+ kind='line',
35
+ completions=False,
36
+ docstring=False,
37
+ generic=False,
38
+ style=True,
39
+ signature=None,
40
+ )
41
+ assert docstring == '\nStyle options\n-------------\n\n' + '\n'.join(
42
+ sorted(Store.registry['matplotlib'][Curve].style_opts)
43
+ )
44
+
45
+ # The current backend becomes plotly
46
+ hvplot.output(backend='plotly')
47
+ docstring, signature = hvplot._get_doc_and_signature(
48
+ cls=hvplot.hvPlot,
49
+ kind='line',
50
+ completions=False,
51
+ docstring=False,
52
+ generic=False,
53
+ style=True,
54
+ signature=None,
55
+ )
56
+ assert docstring == '\nStyle options\n-------------\n\n' + '\n'.join(
57
+ sorted(Store.registry['plotly'][Curve].style_opts)
58
+ )
59
+
60
+
61
+ def test_help_style_compatibility(reset_default_backend):
62
+ # The current backend is plotly but the style options are those of matplotlib
63
+ hvplot.extension('plotly', 'matplotlib', compatibility='matplotlib')
64
+ docstring, signature = hvplot._get_doc_and_signature(
65
+ cls=hvplot.hvPlot,
66
+ kind='line',
67
+ completions=False,
68
+ docstring=False,
69
+ generic=False,
70
+ style=True,
71
+ signature=None,
72
+ )
73
+ assert docstring == '\nStyle options\n-------------\n\n' + '\n'.join(
74
+ sorted(Store.registry['matplotlib'][Curve].style_opts)
75
+ )
@@ -0,0 +1,17 @@
1
+ """Basic ibis tests"""
2
+
3
+ import numpy as np
4
+ import pandas as pd
5
+ import pytest
6
+
7
+ try:
8
+ import hvplot.ibis # noqa
9
+ import ibis
10
+ except ImportError:
11
+ pytest.skip(allow_module_level=True)
12
+
13
+
14
+ def test_ibis_hist():
15
+ df = pd.DataFrame(dict(x=np.arange(10)))
16
+ table = ibis.memtable(df)
17
+ table.hvplot.hist('x')