Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test that no projection is set when tiles is used without geo=True #1113

Merged
merged 7 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/user_guide/Plotting_with_Matplotlib.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
"metadata": {},
"outputs": [],
"source": [
"flights.hvplot.hexbin(x='airtime', y='arrdelay', width=600, height=500, logz=True);"
"# flights.hvplot.hexbin(x='airtime', y='arrdelay', width=600, height=500, logz=True);"
]
},
{
Expand Down Expand Up @@ -461,7 +461,7 @@
"outputs": [],
"source": [
"flight_subset = flights[flights.carrier.isin(['AA', 'US', 'OH'])]\n",
"flight_subset.hvplot.hist('depdelay', by='carrier', bins=20, bin_range=(-20, 100), width=300, subplots=True);"
"# flight_subset.hvplot.hist('depdelay', by='carrier', bins=20, bin_range=(-20, 100), width=300, subplots=True);"
]
},
{
Expand Down Expand Up @@ -575,7 +575,7 @@
"outputs": [],
"source": [
"flight_subset = flights[flights.carrier.isin(['AA', 'US', 'OH'])]\n",
"flight_subset.hvplot.box('depdelay', by='carrier', ylim=(-10, 70));"
"# flight_subset.hvplot.box('depdelay', by='carrier', ylim=(-10, 70));"
]
},
{
Expand Down
37 changes: 37 additions & 0 deletions hvplot/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
optional_markers = {
"geo": {
"help": "Run the tests that require GeoViews",
"marker-descr": "Geo test marker",
"skip-reason": "Test only runs with the --geo option."
},
}


def pytest_addoption(parser):
for marker, info in optional_markers.items():
parser.addoption("--{}".format(marker), action="store_true",
default=False, help=info['help'])


def pytest_configure(config):
for marker, info in optional_markers.items():
config.addinivalue_line("markers",
"{}: {}".format(marker, info['marker-descr']))


def pytest_collection_modifyitems(config, items):
skipped, selected = [], []
markers = [m for m in optional_markers if config.getoption(f"--{m}")]
empty = not markers
for item in items:
if empty and any(m in item.keywords for m in optional_markers):
skipped.append(item)
elif empty:
selected.append(item)
elif not empty and any(m in item.keywords for m in markers):
selected.append(item)
else:
skipped.append(item)

config.hook.pytest_deselected(items=skipped)
items[:] = selected
43 changes: 41 additions & 2 deletions hvplot/tests/testgeo.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
"""
These tests depends on GeoViews.
"""
import pathlib
import sys

from unittest import TestCase, SkipTest

from packaging.version import Version
import holoviews as hv
import numpy as np
import pandas as pd
import holoviews as hv
import pytest

from hvplot.util import proj_to_cartopy
from packaging.version import Version

pytestmark = pytest.mark.geo

bk_renderer = hv.Store.renderers['bokeh']

@pytest.fixture
def simple_df():
return pd.DataFrame(np.random.rand(10, 2), columns=['x', 'y'])


class TestGeo(TestCase):
Expand Down Expand Up @@ -245,6 +257,7 @@ def test_plot_with_features_properly_overlaid_underlaid(self):
assert plot.get(0).group == "Land"
assert plot.get(2).group == "Borders"


class TestGeoElements(TestCase):

def setUp(self):
Expand Down Expand Up @@ -379,3 +392,29 @@ def test_polygons_turns_off_hover_when_there_are_no_fields_to_include(self):
polygons = self.polygons.hvplot(geo=True)
opts = hv.Store.lookup_options('bokeh', polygons, 'plot').kwargs
assert 'hover' not in opts.get('tools')


class TestGeoUtil(TestCase):

def setUp(self):
if sys.platform == "win32":
raise SkipTest("Skip geo tests on windows for now")
try:
import cartopy.crs as ccrs
except:
raise SkipTest('cartopy not available')
self.ccrs = ccrs

def test_proj_to_cartopy(self):
from ..util import proj_to_cartopy
crs = proj_to_cartopy('+init=epsg:26911')

assert isinstance(crs, self.ccrs.CRS)

def test_proj_to_cartopy_wkt_string(self):
from ..util import proj_to_cartopy
crs = proj_to_cartopy('GEOGCRS["unnamed",BASEGEOGCRS["unknown",DATUM["unknown",ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1,ID["EPSG",9001]]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8901]]],DERIVINGCONVERSION["unknown",METHOD["PROJ ob_tran o_proj=latlon"],PARAMETER["o_lon_p",0,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]],PARAMETER["o_lat_p",37.5,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]],PARAMETER["lon_0",357.5,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]]],CS[ellipsoidal,2],AXIS["longitude",east,ORDER[1],ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]],AXIS["latitude",north,ORDER[2],ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]]]') # noqa: E501

assert isinstance(crs, self.ccrs.RotatedPole)
assert crs.proj4_params["lon_0"] == 357.5
assert crs.proj4_params["o_lat_p"] == 37.5
50 changes: 50 additions & 0 deletions hvplot/tests/testgeowithoutgv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Geo tests **without** importing GeoViews.
"""
import holoviews as hv
import hvplot.pandas # noqa
import numpy as np
import pandas as pd
import pytest


bk_renderer = hv.Store.renderers['bokeh']

@pytest.fixture
def simple_df():
return pd.DataFrame(np.random.rand(10, 2), columns=['x', 'y'])


class TestAnnotationNotGeo:

def test_plot_tiles_doesnt_set_geo(self, simple_df):
plot = simple_df.hvplot.points('x', 'y', tiles=True)
assert len(plot) == 2
assert isinstance(plot.get(0), hv.Tiles)
assert 'openstreetmap' in plot.get(0).data
bk_plot = bk_renderer.get_plot(plot)
assert bk_plot.projection == 'mercator'

def test_plot_specific_tiles_doesnt_set_geo(self, simple_df):
plot = simple_df.hvplot.points('x', 'y', tiles='ESRI')
assert len(plot) == 2
assert isinstance(plot.get(0), hv.Tiles)
assert 'ArcGIS' in plot.get(0).data
bk_plot = bk_renderer.get_plot(plot)
assert bk_plot.projection == 'mercator'

def test_plot_with_specific_tile_class(self, simple_df):
plot = simple_df.hvplot.points('x', 'y', tiles=hv.element.tiles.EsriImagery)
assert len(plot) == 2
assert isinstance(plot.get(0), hv.Tiles)
assert 'ArcGIS' in plot.get(0).data
bk_plot = bk_renderer.get_plot(plot)
assert bk_plot.projection == 'mercator'

def test_plot_with_specific_tile_obj(self, simple_df):
plot = simple_df.hvplot.points('x', 'y', tiles=hv.element.tiles.EsriImagery())
assert len(plot) == 2
assert isinstance(plot.get(0), hv.Tiles)
assert 'ArcGIS' in plot.get(0).data
bk_plot = bk_renderer.get_plot(plot)
assert bk_plot.projection == 'mercator'
29 changes: 0 additions & 29 deletions hvplot/tests/testutil.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
Tests utilities to convert data and projections
"""
import sys

import numpy as np
import pandas as pd
import pytest
Expand Down Expand Up @@ -199,33 +197,6 @@ def test_process_xarray_dataset_with_x_as_derived_datetime(self):
assert not groupby


class TestGeoUtil(TestCase):

def setUp(self):
if sys.platform == "win32":
raise SkipTest("Skip geo tests on windows for now")
try:
import geoviews # noqa
import cartopy.crs as ccrs
except:
raise SkipTest('geoviews or cartopy not available')
self.ccrs = ccrs

def test_proj_to_cartopy(self):
from ..util import proj_to_cartopy
crs = proj_to_cartopy('+init=epsg:26911')

assert isinstance(crs, self.ccrs.CRS)

def test_proj_to_cartopy_wkt_string(self):
from ..util import proj_to_cartopy
crs = proj_to_cartopy('GEOGCRS["unnamed",BASEGEOGCRS["unknown",DATUM["unknown",ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1,ID["EPSG",9001]]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8901]]],DERIVINGCONVERSION["unknown",METHOD["PROJ ob_tran o_proj=latlon"],PARAMETER["o_lon_p",0,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]],PARAMETER["o_lat_p",37.5,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]],PARAMETER["lon_0",357.5,ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]]],CS[ellipsoidal,2],AXIS["longitude",east,ORDER[1],ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]],AXIS["latitude",north,ORDER[2],ANGLEUNIT["degree",0.0174532925199433,ID["EPSG",9122]]]]') # noqa: E501

assert isinstance(crs, self.ccrs.RotatedPole)
assert crs.proj4_params["lon_0"] == 357.5
assert crs.proj4_params["o_lat_p"] == 37.5


class TestDynamicArgs(TestCase):

def setUp(self):
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ envlist = {py38,py39,py310,py311}-{unit,examples,all}-{default}-{dev,pkg}
description = Run unit tests with coverage
deps = .[tests]
commands = pytest -v hvplot --cov=./hvplot --cov-append
pytest -v hvplot --geo --cov=./hvplot --cov-append

[_examples]
description = Test that default examples run
Expand Down