From 5db68957b0f8de156c88569ea6b904dbaaf7c281 Mon Sep 17 00:00:00 2001 From: sinhrks Date: Sun, 17 Apr 2016 11:36:08 +0900 Subject: [PATCH] TST: Add pandas tests --- .travis.yml | 2 +- cesiumpy/plotting/tests/test_plotting.py | 104 ++++++++++++++++++++++- cesiumpy/testing.py | 8 ++ 3 files changed, 112 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index edc88f3..5ebc3a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ install: - conda create -q -n test-environment python=$PYTHON pip nose - source activate test-environment - if [[ "$SHAPELY" == "true" ]]; then - conda install numpy scipy shapely fiona matplotlib; + conda install numpy scipy pandas shapely fiona matplotlib; fi - python -m pip install flake8 - python setup.py install diff --git a/cesiumpy/plotting/tests/test_plotting.py b/cesiumpy/plotting/tests/test_plotting.py index d203356..c06800e 100644 --- a/cesiumpy/plotting/tests/test_plotting.py +++ b/cesiumpy/plotting/tests/test_plotting.py @@ -5,7 +5,8 @@ import unittest import cesiumpy -from cesiumpy.testing import _skip_if_no_numpy, _skip_if_no_matplotlib +from cesiumpy.testing import (_skip_if_no_numpy, _skip_if_no_pandas, + _skip_if_no_matplotlib) class TestScatter(unittest.TestCase): @@ -120,6 +121,42 @@ def test_scatter_errors(self): with nose.tools.assert_raises_regexp(ValueError, msg): v.plot.scatter([130, 140, 150], [30, 40, 50], size=[1, 2]) + def test_scatter_pandas(self): + _skip_if_no_pandas() + import pandas as pd + df = pd.DataFrame({'lon': [130, 140, 150], + 'lat': [50, 60, 70], + 'r': [10, 20, 30], + 'c': ['r', 'g', 'b']}) + # we can't use size column + v = cesiumpy.Viewer(divid='viewertest') + v.plot.scatter(x=df.lon, y=df.lat, size=df.r) + exp = """ + +
+""" + self.assertEqual(v.to_html(), exp) + + v = cesiumpy.Viewer(divid='viewertest') + v.plot.scatter(x=df.lon, y=df.lat, size=df.r, color=df.c) + exp = """ + +
+""" + self.assertEqual(v.to_html(), exp) + class TestBar(unittest.TestCase): @@ -218,6 +255,27 @@ def test_bar_bottom(self): """ self.assertEqual(v.to_html(), exp) + def test_bar_pandas(self): + _skip_if_no_pandas() + import pandas as pd + df = pd.DataFrame({'lon': [130, 140, 150], + 'lat': [50, 60, 70], + 'h': [1e5, 2e5, 3e5], + 'c': ['r', 'g', 'b']}) + v = cesiumpy.Viewer(divid='viewertest') + v.plot.bar(x=df.lon, y=df.lat, z=df.h, color=df.c) + exp = """ + +
+""" + self.assertEqual(v.to_html(), exp) + class TestLabel(unittest.TestCase): @@ -327,6 +385,28 @@ def test_label_size_list(self): """ self.assertEqual(v.to_html(), exp) + def test_label_pandas(self): + _skip_if_no_pandas() + import pandas as pd + df = pd.DataFrame({'lon': [130, 140, 150], + 'lat': [50, 60, 70], + 's': [1, 2, 3], + 'label': ['a', 'b', 'c'], + 'c': ['r', 'g', 'b']}) + v = cesiumpy.Viewer(divid='viewertest') + v.plot.label(df.label, x=df.lon, y=df.lat, size=df.s, color=df.c) + exp = """ + +
+""" + self.assertEqual(v.to_html(), exp) + class TestPin(unittest.TestCase): @@ -547,6 +627,28 @@ def test_contour_xyz(self): self.assertEqual(viewer.entities[0].material, cesiumpy.color.Color(0.0, 0.0, 0.5, 1.0)) + def test_pin_pandas(self): + _skip_if_no_pandas() + import pandas as pd + df = pd.DataFrame({'lon': [130, 140, 150], + 'lat': [50, 60, 70], + 's': [10, 20, 30], + 'label': ['a', 'b', 'c'], + 'c': ['r', 'g', 'b']}) + v = cesiumpy.Viewer(divid='viewertest') + v.plot.pin(x=df.lon, y=df.lat, size=df.s, color=df.c, text=df.label) + exp = """ + +
+""" + self.assertEqual(v.to_html(), exp) + if __name__ == '__main__': nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], diff --git a/cesiumpy/testing.py b/cesiumpy/testing.py index 629c7a0..7b567bd 100644 --- a/cesiumpy/testing.py +++ b/cesiumpy/testing.py @@ -12,6 +12,14 @@ def _skip_if_no_numpy(): raise nose.SkipTest("no numpy module") +def _skip_if_no_pandas(): + try: + import pandas # noqa + except ImportError: + import nose + raise nose.SkipTest("no pandas module") + + def _skip_if_no_scipy(): try: import scipy.spatial # noqa