#-----------------------------------------------------------------------------# Copyright (c) 2012 - 2023, 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:# XXX: groupby.groupby possibly due to a bug in import following in mypyfrompandasimportDataFrame# noqa: F401frompandas.core.groupby.groupbyimportGroupBy# noqa: F401#-----------------------------------------------------------------------------# Globals and constants#-----------------------------------------------------------------------------__all__=('PandasDataFrame','PandasGroupBy',)#-----------------------------------------------------------------------------# General API#-----------------------------------------------------------------------------
[docs]classPandasDataFrame(Property["DataFrame"]):""" 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)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)importpandasaspdifisinstance(value,pd.core.groupby.GroupBy):# type: ignorereturnmsg=""ifnotdetailelsef"expected Pandas GroupBy, got {value!r}"raiseValueError(msg)
#-----------------------------------------------------------------------------# Dev API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Private API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Code#-----------------------------------------------------------------------------