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

checks geodataframe for crs before conversion #1459

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,7 @@ def _process_tiles_without_geo(self, data, x, y):
return data, x, y

if is_geodataframe(data):
if data.crs is not None:
if hasattr(data, 'crs') and data.crs is not None:
data = data.to_crs(epsg=3857)
return data, x, y
elif not is_lazy_data(data):
Expand Down
20 changes: 20 additions & 0 deletions hvplot/tests/testgeowithoutgv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import numpy as np
import pandas as pd
import pytest
import spatialpandas as spd

from hvplot.util import is_geodataframe

try:
import dask.dataframe as dd
Expand Down Expand Up @@ -83,3 +86,20 @@ def test_plot_with_dask(self, simple_df):
assert isinstance(plot.get(0), hv.Tiles)
bk_plot = bk_renderer.get_plot(plot)
assert bk_plot.projection == 'mercator'

@pytest.mark.skipif(spd is None, reason='spatialpandas not installed')
def test_plot_without_crs(self):
square = spd.geometry.Polygon([(0.0, 0), (0, 1), (1, 1), (1, 0)])
sdf = spd.GeoDataFrame({'geometry': spd.GeoSeries([square, square]), 'name': ['A', 'B']})
plot = sdf.hvplot.polygons(tiles=True)

if hasattr(sdf, 'crs'):
del sdf.crs
hoxbro marked this conversation as resolved.
Show resolved Hide resolved

assert len(plot) == 2
assert is_geodataframe(sdf)
assert not hasattr(plot, 'crs')
assert isinstance(plot.get(0), hv.Tiles)
assert isinstance(plot.get(1), hv.Polygons)
bk_plot = bk_renderer.get_plot(plot)
assert bk_plot.projection == 'mercator'
ahuang11 marked this conversation as resolved.
Show resolved Hide resolved
Loading