From 382215ad7012a875ab56beeb01e74d2b605cebef Mon Sep 17 00:00:00 2001 From: Simon Hoxbro Date: Mon, 30 May 2022 21:29:31 +0200 Subject: [PATCH 1/4] Adding geodataframe to DataConversion --- holoviews/core/data/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/holoviews/core/data/__init__.py b/holoviews/core/data/__init__.py index 86b54f2573..f9b6a59392 100644 --- a/holoviews/core/data/__init__.py +++ b/holoviews/core/data/__init__.py @@ -129,7 +129,8 @@ def __call__(self, new_type, kdims=None, vdims=None, groupby=None, else: selected = self._element else: - if pd and issubclass(self._element.interface, PandasInterface): + df_interfaces = tuple(v for k, v in Interface.interfaces.items() if "dataframe" in k.lower()) + if issubclass(self._element.interface, df_interfaces): ds_dims = self._element.dimensions() ds_kdims = [self._element.get_dimension(d) if d in ds_dims else d for d in groupby+kdims] From e7ed7cdc0dcfa9a39532796eec84ad6f747eef3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Thu, 9 Mar 2023 09:22:38 +0100 Subject: [PATCH 2/4] Update if statement to be more explicit --- holoviews/core/data/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/holoviews/core/data/__init__.py b/holoviews/core/data/__init__.py index 25a0a6f4e3..4c26b92a31 100644 --- a/holoviews/core/data/__init__.py +++ b/holoviews/core/data/__init__.py @@ -27,7 +27,7 @@ from .interface import Interface, iloc, ndloc from .multipath import MultiInterface # noqa (API import) from .image import ImageInterface # noqa (API import) -from .pandas import PandasInterface +from .pandas import PandasInterface # noqa (API import) from .spatialpandas import SpatialPandasInterface # noqa (API import) from .spatialpandas_dask import DaskSpatialPandasInterface # noqa (API import) from .xarray import XArrayInterface # noqa (API import) @@ -124,7 +124,11 @@ def __call__(self, new_type, kdims=None, vdims=None, groupby=None, else: selected = self._element else: - df_interfaces = tuple(v for k, v in Interface.interfaces.items() if "dataframe" in k.lower()) + df_interfaces = tuple( + v + for k, v in Interface.interfaces.items() + if k.lower() in ('dataframe', 'geodataframe') + ) if issubclass(self._element.interface, df_interfaces): ds_dims = self._element.dimensions() ds_kdims = [self._element.get_dimension(d) if d in ds_dims else d From 334268205ea188f3d3fa531d772dd0f572909cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Thu, 16 Mar 2023 09:29:44 +0100 Subject: [PATCH 3/4] Add PandasApi --- holoviews/core/data/__init__.py | 9 ++------- holoviews/core/data/pandas.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/holoviews/core/data/__init__.py b/holoviews/core/data/__init__.py index 4c26b92a31..07fb6518ac 100644 --- a/holoviews/core/data/__init__.py +++ b/holoviews/core/data/__init__.py @@ -27,7 +27,7 @@ from .interface import Interface, iloc, ndloc from .multipath import MultiInterface # noqa (API import) from .image import ImageInterface # noqa (API import) -from .pandas import PandasInterface # noqa (API import) +from .pandas import PandasApi, PandasInterface # noqa (API import) from .spatialpandas import SpatialPandasInterface # noqa (API import) from .spatialpandas_dask import DaskSpatialPandasInterface # noqa (API import) from .xarray import XArrayInterface # noqa (API import) @@ -124,12 +124,7 @@ def __call__(self, new_type, kdims=None, vdims=None, groupby=None, else: selected = self._element else: - df_interfaces = tuple( - v - for k, v in Interface.interfaces.items() - if k.lower() in ('dataframe', 'geodataframe') - ) - if issubclass(self._element.interface, df_interfaces): + if issubclass(self._element.interface, PandasApi): ds_dims = self._element.dimensions() ds_kdims = [self._element.get_dimension(d) if d in ds_dims else d for d in groupby+kdims] diff --git a/holoviews/core/data/pandas.py b/holoviews/core/data/pandas.py index 383593d21f..6c3d4a6375 100644 --- a/holoviews/core/data/pandas.py +++ b/holoviews/core/data/pandas.py @@ -14,7 +14,20 @@ from .util import finite_range -class PandasInterface(Interface): +class PandasApi: + """ + This class is used to describe the interface as having a pandas-like API. + + The reason to have this class is that it is not always + possible to directly inherit from the PandasInterface. + + This class should not have any logic as it should be used like: + if issubclass(interface, PandasApi): + ... + """ + + +class PandasInterface(Interface, PandasApi): types = (pd.DataFrame,) From 6eaab760391ba20de54c6e693eb6850d7071877f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Fri, 31 Mar 2023 16:29:48 +0200 Subject: [PATCH 4/4] PandasApi -> PandasAPI --- holoviews/core/data/__init__.py | 4 ++-- holoviews/core/data/pandas.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/holoviews/core/data/__init__.py b/holoviews/core/data/__init__.py index 07fb6518ac..cd73b7048c 100644 --- a/holoviews/core/data/__init__.py +++ b/holoviews/core/data/__init__.py @@ -27,7 +27,7 @@ from .interface import Interface, iloc, ndloc from .multipath import MultiInterface # noqa (API import) from .image import ImageInterface # noqa (API import) -from .pandas import PandasApi, PandasInterface # noqa (API import) +from .pandas import PandasAPI, PandasInterface # noqa (API import) from .spatialpandas import SpatialPandasInterface # noqa (API import) from .spatialpandas_dask import DaskSpatialPandasInterface # noqa (API import) from .xarray import XArrayInterface # noqa (API import) @@ -124,7 +124,7 @@ def __call__(self, new_type, kdims=None, vdims=None, groupby=None, else: selected = self._element else: - if issubclass(self._element.interface, PandasApi): + if issubclass(self._element.interface, PandasAPI): ds_dims = self._element.dimensions() ds_kdims = [self._element.get_dimension(d) if d in ds_dims else d for d in groupby+kdims] diff --git a/holoviews/core/data/pandas.py b/holoviews/core/data/pandas.py index 6c3d4a6375..8e54d609d4 100644 --- a/holoviews/core/data/pandas.py +++ b/holoviews/core/data/pandas.py @@ -14,7 +14,7 @@ from .util import finite_range -class PandasApi: +class PandasAPI: """ This class is used to describe the interface as having a pandas-like API. @@ -22,12 +22,12 @@ class PandasApi: possible to directly inherit from the PandasInterface. This class should not have any logic as it should be used like: - if issubclass(interface, PandasApi): + if issubclass(interface, PandasAPI): ... """ -class PandasInterface(Interface, PandasApi): +class PandasInterface(Interface, PandasAPI): types = (pd.DataFrame,)