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

Return nans for range if column can't find min and max #723

Merged
merged 2 commits into from
Jun 22, 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
5 changes: 4 additions & 1 deletion geoviews/data/geopandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ def range(cls, dataset, dim):
return bounds.miny.min(), bounds.maxy.max()
else:
vals = dataset.data[dim.name]
return vals.min(), vals.max()
try:
return vals.min(), vals.max()
except TypeError:
return np.nan, np.nan

@classmethod
def aggregate(cls, columns, dimensions, function, **kwargs):
Expand Down
13 changes: 13 additions & 0 deletions geoviews/tests/data/test_geopandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
except ImportError:
geopandas = None

from holoviews import render
from holoviews.core.data import Dataset
from holoviews.core.data.interface import DataError
from holoviews.element import Polygons, Path, Points
Expand Down Expand Up @@ -202,3 +203,15 @@ def test_geometry_column_not_named_geometry_and_additional_geometry_column(self)
ds = Dataset(gdf, kdims=['Longitude', 'Latitude'], datatype=[self.datatype])
self.assertEqual(ds.dimension_values('Longitude'), np.array([0, 1]))
self.assertEqual(ds.dimension_values('Latitude'), np.array([1, 2]))

def test_geopandas_dataframe_with_different_dtype_column(self):
# Fix for https://github.com/holoviz/geoviews/issues/721
df = pd.DataFrame(
{
"x": [1, 2, 3, 4, 5],
"y": [1, 2, 3, 4, 5],
"value": [5, '4', 3, 2, 1],
}
)
gdf = geopandas.GeoDataFrame(df, geometry=geopandas.points_from_xy(df.x, df.y))
render(Points(gdf))
Loading