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 4 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
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
ahuang11 marked this conversation as resolved.
Show resolved Hide resolved

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other thought are these can be moved up, and the pytest.mark.skipif can check if dd or spd is None.

Suggested change
import dask.dataframe as dd
import spatialpandas as spd

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Done


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
ahuang11 marked this conversation as resolved.
Show resolved Hide resolved

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