#-----------------------------------------------------------------------------# Copyright (c) Anaconda, Inc., and Bokeh Contributors.# All rights reserved.## The full license is in the file LICENSE.txt, distributed with this software.#-----------------------------------------------------------------------------""" Provide (optional) Pandas properties."""#-----------------------------------------------------------------------------# Boilerplate#-----------------------------------------------------------------------------from__future__importannotationsimportlogging# isort:skiplog=logging.getLogger(__name__)#-----------------------------------------------------------------------------# Imports#-----------------------------------------------------------------------------# Standard library importsfromtypingimportTYPE_CHECKING,Any# Bokeh importsfrom.basesimportPropertyifTYPE_CHECKING:fromnarwhals.stable.v1.typingimportIntoDataFrame,IntoSeries# noqa: F401frompandasimportDataFrame# noqa: F401frompandas.core.groupbyimportGroupBy# noqa: F401#-----------------------------------------------------------------------------# Globals and constants#-----------------------------------------------------------------------------__all__=('EagerDataFrame','EagerSeries','PandasDataFrame','PandasGroupBy',)#-----------------------------------------------------------------------------# General API#-----------------------------------------------------------------------------
[docs]classEagerDataFrame(Property["IntoDataFrame"]):""" Accept eager dataframe supported by Narwhals. This property only exists to support type validation, e.g. for "accepts" clauses. It is not serializable itself, and is not useful to add to Bokeh models directly. """defvalidate(self,value:Any,detail:bool=True)->None:importnarwhals.stable.v1asnwsuper().validate(value,detail)ifnw.dependencies.is_into_dataframe(value):return# type: ignore[unreachable] # https://github.com/bokeh/bokeh/issues/14342msg=""ifnotdetailelsef"expected object convertible to Narwhals DataFrame, got {value!r}"raiseValueError(msg)
[docs]classEagerSeries(Property["IntoSeries"]):""" Accept eager series supported by Narwhals. This property only exists to support type validation, e.g. for "accepts" clauses. It is not serializable itself, and is not useful to add to Bokeh models directly. """defvalidate(self,value:Any,detail:bool=True)->None:importnarwhals.stable.v1asnwsuper().validate(value,detail)ifnw.dependencies.is_into_series(value):return# type: ignore[unreachable] # https://github.com/bokeh/bokeh/issues/14342msg=""ifnotdetailelsef"expected object convertible to Narwhals Series, got {value!r}"raiseValueError(msg)
[docs]classPandasDataFrame(Property["DataFrame"]):""" Accept Pandas DataFrame values. This class is pandas-specific - are more generic one is ``EagerDataFrame()``. This property only exists to support type validation, e.g. for "accepts" clauses. It is not serializable itself, and is not useful to add to Bokeh models directly. """def__init__(self)->None:super().__init__()defvalidate(self,value:Any,detail:bool=True)->None:importpandasaspdifisinstance(value,pd.DataFrame):returnmsg=""ifnotdetailelsef"expected Pandas DataFrame, got {value!r}"raiseValueError(msg)
[docs]classPandasGroupBy(Property["GroupBy[Any]"]):""" Accept Pandas DataFrame values. This property only exists to support type validation, e.g. for "accepts" clauses. It is not serializable itself, and is not useful to add to Bokeh models directly. """defvalidate(self,value:Any,detail:bool=True)->None:super().validate(value,detail)frompandas.core.groupbyimportGroupByifisinstance(value,GroupBy):returnmsg=""ifnotdetailelsef"expected Pandas GroupBy, got {value!r}"raiseValueError(msg)
#-----------------------------------------------------------------------------# Dev API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Private API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Code#-----------------------------------------------------------------------------