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

Added daskgeopandas check to is_geodataframe function #1395

Closed
wants to merge 3 commits into from
Closed
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
33 changes: 30 additions & 3 deletions hvplot/tests/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
import panel as pn
import pytest

try:
import spatialpandas
import dask
except ImportError:
spatialpandas = None
dask = None

from unittest import TestCase, SkipTest

from hvplot.util import (
Expand All @@ -16,6 +23,7 @@
process_xarray,
_convert_col_names_to_str,
instantiate_crs_str,
is_geodataframe,
)


Expand Down Expand Up @@ -184,7 +192,7 @@ def test_process_xarray_dataset_with_x_as_derived_datetime(self):

class TestDynamicArgs(TestCase):
def test_dynamic_and_static(self):
from ..util import process_dynamic_args
from hvplot.util import process_dynamic_args

x = 'sepal_width'
y = pn.widgets.Select(
Expand All @@ -198,7 +206,7 @@ def test_dynamic_and_static(self):
assert arg_deps == []

def test_dynamic_kwds(self):
from ..util import process_dynamic_args
from hvplot.util import process_dynamic_args

x = 'sepal_length'
y = 'sepal_width'
Expand All @@ -211,7 +219,7 @@ def test_dynamic_kwds(self):
assert arg_deps == []

def test_fn_kwds(self):
from ..util import process_dynamic_args
from hvplot.util import process_dynamic_args

x = 'sepal_length'
y = 'sepal_width'
Expand Down Expand Up @@ -361,3 +369,22 @@ def test_instantiate_crs_str_kwargs():
assert isinstance(crs, ccrs.PlateCarree)
assert isinstance(crs.globe, ccrs.Globe)
assert crs.globe.datum == 'WGS84'


@pytest.mark.skipif(
spatialpandas is None or dask is None, reason='spatialpandas or dask is not available'
)
def test_is_geodataframe_spatialpandas_dask():
import dask.dataframe as dd
import spatialpandas as spd

square = spd.geometry.Polygon([(0.0, 0), (0, 1), (1, 1), (1, 0)])
sdf = spd.GeoDataFrame({'geometry': spd.GeoSeries([square, square]), 'name': ['A', 'B']})
sddf = dd.from_pandas(sdf, npartitions=2)
assert isinstance(sddf, spd.dask.DaskGeoDataFrame)
assert is_geodataframe(sddf)


def test_is_geodataframe_classic_dataframe():
df = pd.DataFrame({'geometry': [None, None], 'name': ['A', 'B']})
assert not is_geodataframe(df)
3 changes: 2 additions & 1 deletion hvplot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,9 @@ def process_intake(data, use_dask):
def is_geodataframe(data):
if 'spatialpandas' in sys.modules:
import spatialpandas as spd
from spatialpandas.dask import DaskGeoDataFrame

if isinstance(data, spd.GeoDataFrame):
if isinstance(data, (spd.GeoDataFrame, DaskGeoDataFrame)):
return True
return (
isinstance(data, pd.DataFrame) and hasattr(data, 'geom_type') and hasattr(data, 'geometry')
Expand Down