11from typing import Optional , List
2+ from collections import UserDict
23
34from validator_collection import validators , checkers
45
@@ -846,20 +847,21 @@ def from_pandas(cls,
846847 options_kwargs = None ,
847848 chart_kwargs = None ,
848849 series_in_rows = False ,
850+ series_index = None ,
849851 ** kwargs ):
850852 """Create a :class:`Chart <highcharts_core.chart.Chart>` instance whose
851853 data is populated from a `pandas <https://pandas.pydata.org/>`_
852- :class:`DataFrame <pandas:DataFrame>`.
854+ :class:`DataFrame <pandas:pandas. DataFrame>`.
853855
854- :param df: The :class:`DataFrame <pandas:DataFrame>` from which data should be
856+ :param df: The :class:`DataFrame <pandas:pandas. DataFrame>` from which data should be
855857 loaded.
856- :type df: :class:`DataFrame <pandas:DataFrame>`
858+ :type df: :class:`DataFrame <pandas:pandas. DataFrame>`
857859
858860 :param property_map: A :class:`dict <python:dict>` used to indicate which
859861 data point property should be set to which column in ``df``. The keys in the
860862 :class:`dict <python:dict>` should correspond to properties in the data point
861863 class, while the value should indicate the label for the
862- :class:`DataFrame <pandas:DataFrame>` column. Defaults to
864+ :class:`DataFrame <pandas:pandas. DataFrame>` column. Defaults to
863865 :obj:`None <python:None>`.
864866 :type property_map: :class:`dict <python:dict>`
865867
@@ -907,6 +909,14 @@ def from_pandas(cls,
907909 :obj:`False <python:False>`.
908910 :type series_in_rows: :class:`bool <python:bool>`
909911
912+ :param series_index: If supplied, generate the chart with the series that
913+ Highcharts for Python generated from ``df`` at the ``series_index`` position.
914+ Defaults to :obj:`None <python:None>`, which includes all series generated
915+ from ``df`` on the chart.
916+
917+ :type series_index: :class:`int <python:int>`, slice, or
918+ :obj:`None <python:None>`
919+
910920 :param **kwargs: Additional keyword arguments that are - in turn - propagated to
911921 the series created from the ``df``.
912922
@@ -919,27 +929,43 @@ def from_pandas(cls,
919929 :raises HighchartsDependencyError: if `pandas <https://pandas.pydata.org/>`_ is
920930 not available in the runtime environment
921931 """
922- series_type = validators .string (series_type , allow_empty = False )
923- series_type = series_type .lower ()
932+ if not series_type :
933+ raise errors .HighchartsValueError ('series_type cannot be empty' )
934+ series_type = str (series_type ).lower ()
924935 if series_type not in SERIES_CLASSES :
925936 raise errors .HighchartsValueError (f'series_type expects a valid Highcharts '
926937 f'series type. Received: { series_type } ' )
927938
928- options_kwargs = validators .dict (options_kwargs , allow_empty = True ) or {}
929- chart_kwargs = validators .dict (chart_kwargs , allow_empty = True ) or {}
930- kwargs = validators .dict (kwargs , allow_empty = True ) or {}
939+ if not isinstance (options_kwargs , (dict , UserDict , type (None ))):
940+ raise errors .HighchartsValueError (f'options_kwarts expects a dict. '
941+ f'Received: { options_kwargs .__class__ .__name__ } ' )
942+ if not options_kwargs :
943+ options_kwargs = {}
944+
945+ if not isinstance (chart_kwargs , (dict , UserDict , type (None ))):
946+ raise errors .HighchartsValueError (f'chart_kwargs expects a dict. '
947+ f'Received: { chart_kwargs .__class__ .__name__ } ' )
948+ if not chart_kwargs :
949+ chart_kwargs = {}
950+
951+ if not isinstance (kwargs , (dict , UserDict , type (None ))):
952+ raise errors .HighchartsValueError (f'kwargs expects a dict. '
953+ f'Received: { kwargs .__class__ .__name__ } ' )
954+ if not kwargs :
955+ kwargs = {}
931956
932957 series_cls = SERIES_CLASSES .get (series_type , None )
933958
934959 if series_in_rows :
935960 series = series_cls .from_pandas_in_rows (df ,
936961 series_kwargs = series_kwargs ,
937- options_kwargs = options_kwargs ,
962+ series_index = series_index ,
938963 ** kwargs )
939964 else :
940965 series = series_cls .from_pandas (df ,
941966 property_map = property_map ,
942967 series_kwargs = series_kwargs ,
968+ series_index = series_index ,
943969 ** kwargs )
944970
945971 if isinstance (series , series_cls ):
0 commit comments