From bbe52f1ee9716af6cbfb3665ffc9faaeff2ebbe1 Mon Sep 17 00:00:00 2001 From: Nabarun Pal Date: Tue, 21 Aug 2018 06:48:19 +0530 Subject: [PATCH 1/3] Adds support for named data This fixes the current build errors due to a change in how Altair interprets inline data. More information on y#33 --- mplaltair/_data.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mplaltair/_data.py b/mplaltair/_data.py index 55dc6bc..e49fad6 100644 --- a/mplaltair/_data.py +++ b/mplaltair/_data.py @@ -34,6 +34,8 @@ def _normalize_data(chart): df = pd.DataFrame(_fetch(spec['data']['url'])) elif spec['data'].get('values'): return + elif spec['data'].get('name'): + return else: raise NotImplementedError('Given data specification is unsupported at the moment.') From eea8017308665752e4ebcbbc16470b955808addf Mon Sep 17 00:00:00 2001 From: Nabarun Pal Date: Tue, 21 Aug 2018 23:58:12 +0530 Subject: [PATCH 2/3] Adds a check to the named data set validator --- mplaltair/_data.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mplaltair/_data.py b/mplaltair/_data.py index e49fad6..a4db962 100644 --- a/mplaltair/_data.py +++ b/mplaltair/_data.py @@ -35,7 +35,11 @@ def _normalize_data(chart): elif spec['data'].get('values'): return elif spec['data'].get('name'): - return + datasets = spec['datasets'] + if spec['data'].get('name') in datasets.keys(): + return + else: + raise ValidationError('Named Data is provided but no corresponding dataset is found') else: raise NotImplementedError('Given data specification is unsupported at the moment.') From 56ff62b3202a263bb3f43decd72aad000cae2457 Mon Sep 17 00:00:00 2001 From: Nabarun Pal Date: Wed, 22 Aug 2018 00:19:54 +0530 Subject: [PATCH 3/3] Adds test to catch the error when named data is provided without any data --- mplaltair/_data.py | 2 +- mplaltair/tests/test_data.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mplaltair/_data.py b/mplaltair/_data.py index a4db962..ade8a35 100644 --- a/mplaltair/_data.py +++ b/mplaltair/_data.py @@ -35,7 +35,7 @@ def _normalize_data(chart): elif spec['data'].get('values'): return elif spec['data'].get('name'): - datasets = spec['datasets'] + datasets = spec.get('datasets', {}) if spec['data'].get('name') in datasets.keys(): return else: diff --git a/mplaltair/tests/test_data.py b/mplaltair/tests/test_data.py index 0f4871d..3674b93 100644 --- a/mplaltair/tests/test_data.py +++ b/mplaltair/tests/test_data.py @@ -2,6 +2,7 @@ import pandas as pd import matplotlib.dates as mdates import mplaltair._data as _data +from mplaltair._exceptions import ValidationError import pytest from vega_datasets import data @@ -26,6 +27,11 @@ def test_data_url(): _data._normalize_data(chart) assert type(chart.data) == pd.DataFrame +def test_named_data(): + chart = alt.Chart(alt.NamedData('test-dataset')).mark_point() + with pytest.raises(ValidationError): + _data._normalize_data(chart) + # test date conversion: df_nonstandard = pd.DataFrame({