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 #1396

Merged
merged 7 commits into from
Sep 11, 2024
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
1 change: 1 addition & 0 deletions envs/py3.10-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dependencies:
- scipy>=1.5.3
- selenium>=3.141.0
- setuptools_scm>=6
- spatialpandas
- spatialpandas>=0.4.3
- sqlglot
- streamz>=0.3.0
Expand Down
1 change: 1 addition & 0 deletions envs/py3.11-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dependencies:
- scipy>=1.5.3
- selenium>=3.141.0
- setuptools_scm>=6
- spatialpandas
- spatialpandas>=0.4.3
- sqlglot
- streamz>=0.3.0
Expand Down
1 change: 1 addition & 0 deletions envs/py3.12-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dependencies:
- scipy>=1.5.3
- selenium>=3.141.0
- setuptools_scm>=6
- spatialpandas
- spatialpandas>=0.4.3
- sqlglot
- streamz>=0.3.0
Expand Down
1 change: 1 addition & 0 deletions envs/py3.9-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dependencies:
- scipy>=1.5.3
- selenium>=3.141.0
- setuptools_scm>=6
- spatialpandas
- spatialpandas>=0.4.3
- sqlglot
- streamz>=0.3.0
Expand Down
28 changes: 25 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 dask.dataframe as dd
import spatialpandas as spd
except ImportError:
spd = None
dd = 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,17 @@ 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(spd is None or dd is None, reason='spatialpandas or dask is not available')
def test_is_geodataframe_spatialpandas_dask():
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)
2 changes: 1 addition & 1 deletion hvplot/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def is_geodataframe(data):
if 'spatialpandas' in sys.modules:
import spatialpandas as spd

if isinstance(data, spd.GeoDataFrame):
if isinstance(data, (spd.GeoDataFrame, spd.dask.DaskGeoDataFrame)):
return True
return (
isinstance(data, pd.DataFrame) and hasattr(data, 'geom_type') and hasattr(data, 'geometry')
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ tests = [
# end fugue
"ibis-framework[duckdb]", # ibis-duckdb on conda
"polars",
"dask",
"spatialpandas",
]
# In 0.9 fugue added the sql extra but didn't add a fugue-sql package, removing the sql deps from fugue
# Adding them manually here
Expand Down
Loading