File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 11from ._exceptions import ValidationError
22
3+ import pandas as pd
4+
5+ from ._utils import _fetch
6+
7+ def _normalize_data (spec ):
8+ """Converts the data to a Pandas dataframe
9+
10+ Parameters
11+ ----------
12+ spec : dict
13+ The vega-lite specification in json format
14+
15+ Returns
16+ -------
17+ dict
18+ The vega-lite specification with the data format fixed to a Pandas dataframe
19+
20+ Raises
21+ ------
22+ ValidationError
23+ Raised when the specification does not contain any data attribute
24+
25+ NotImplementedError
26+ Raised when the data specification has an unsupported data source
27+ """
28+
29+ if not spec .get ('data' ):
30+ raise ValidationError ('Please specify a data source.' )
31+
32+ if spec ['data' ].get ('url' ):
33+ df = pd .DataFrame (_fetch (spec ['data' ]['url' ]))
34+ elif spec ['data' ].get ('values' ):
35+ df = pd .DataFrame (spec ['data' ]['values' ])
36+ else :
37+ raise NotImplementedError ('Given data specification is unsupported at the moment.' )
38+
39+ del spec ['data' ]
40+ spec ['data' ] = df
41+
42+ return spec
43+
344def _locate_channel_dtype (chart , channel ):
445 """Locates dtype used for each channel
546 Parameters
You can’t perform that action at this time.
0 commit comments