11from typing import Optional , List
2+ from collections import UserDict
23
34from validator_collection import validators , checkers
45
@@ -646,6 +647,7 @@ def from_csv(cls,
646647 escape_character = "\\ " ,
647648 is_maps_chart = False ,
648649 series_in_rows = False ,
650+ series_index = None ,
649651 ** kwargs ):
650652 """Create a new :class:`Chart <highcharts_core.chart.Chart>` instance with
651653 data populated from a CSV string or file.
@@ -801,6 +803,14 @@ def from_csv(cls,
801803 the series name taken from the row index. Defaults to ``False``.
802804 :type series_in_rows: :class:`bool <python:bool>`
803805
806+ :param series_index: If supplied, generate the chart with the series that
807+ Highcharts for Python generated from ``df`` at the ``series_index`` position.
808+ Defaults to :obj:`None <python:None>`, which includes all series generated
809+ from ``df`` on the chart.
810+
811+ :type series_index: :class:`int <python:int>`, slice, or
812+ :obj:`None <python:None>`
813+
804814 :param **kwargs: Remaining keyword arguments will be attempted on the resulting
805815 :term:`series` instance and the data points it contains.
806816
@@ -818,8 +828,23 @@ def from_csv(cls,
818828 raise errors .HighchartsValueError (f'series_type expects a valid Highcharts '
819829 f'series type. Received: { series_type } ' )
820830
821- options_kwargs = validators .dict (options_kwargs , allow_empty = True ) or {}
822- chart_kwargs = validators .dict (chart_kwargs , allow_empty = True ) or {}
831+ if not isinstance (options_kwargs , (dict , UserDict , type (None ))):
832+ raise errors .HighchartsValueError (f'options_kwarts expects a dict. '
833+ f'Received: { options_kwargs .__class__ .__name__ } ' )
834+ if not options_kwargs :
835+ options_kwargs = {}
836+
837+ if not isinstance (chart_kwargs , (dict , UserDict , type (None ))):
838+ raise errors .HighchartsValueError (f'chart_kwargs expects a dict. '
839+ f'Received: { chart_kwargs .__class__ .__name__ } ' )
840+ if not chart_kwargs :
841+ chart_kwargs = {}
842+
843+ if not isinstance (kwargs , (dict , UserDict , type (None ))):
844+ raise errors .HighchartsValueError (f'kwargs expects a dict. '
845+ f'Received: { kwargs .__class__ .__name__ } ' )
846+ if not kwargs :
847+ kwargs = {}
823848
824849 chart_kwargs ['is_maps_chart' ] = bool (is_maps_chart )
825850
@@ -837,6 +862,7 @@ def from_csv(cls,
837862 wrap_all_strings = wrap_all_strings ,
838863 double_wrapper_character_when_nested = double_wrapper_character_when_nested ,
839864 escape_character = escape_character ,
865+ series_index = series_index ,
840866 ** kwargs
841867 )
842868 else :
@@ -851,6 +877,7 @@ def from_csv(cls,
851877 wrap_all_strings = wrap_all_strings ,
852878 double_wrapper_character_when_nested = double_wrapper_character_when_nested ,
853879 escape_character = escape_character ,
880+ series_index = series_index ,
854881 ** kwargs )
855882
856883 if not isinstance (series , list ):
@@ -874,6 +901,7 @@ def from_pandas(cls,
874901 options_kwargs = None ,
875902 chart_kwargs = None ,
876903 series_in_rows = False ,
904+ series_index = None ,
877905 ** kwargs ):
878906 """Create a :class:`Chart <highcharts_core.chart.Chart>` instance whose
879907 data is populated from a `pandas <https://pandas.pydata.org/>`_
@@ -935,6 +963,14 @@ def from_pandas(cls,
935963 :obj:`False <python:False>`.
936964 :type series_in_rows: :class:`bool <python:bool>`
937965
966+ :param series_index: If supplied, generate the chart with the series that
967+ Highcharts for Python generated from ``df`` at the ``series_index`` position.
968+ Defaults to :obj:`None <python:None>`, which includes all series generated
969+ from ``df`` on the chart.
970+
971+ :type series_index: :class:`int <python:int>`, slice, or
972+ :obj:`None <python:None>`
973+
938974 :param **kwargs: Additional keyword arguments that are - in turn - propagated to
939975 the series created from the ``df``.
940976
@@ -962,12 +998,13 @@ def from_pandas(cls,
962998 if series_in_rows :
963999 series = series_cls .from_pandas_in_rows (df ,
9641000 series_kwargs = series_kwargs ,
965- options_kwargs = options_kwargs ,
1001+ series_index = series_index ,
9661002 ** kwargs )
9671003 else :
9681004 series = series_cls .from_pandas (df ,
9691005 property_map = property_map ,
9701006 series_kwargs = series_kwargs ,
1007+ series_index = series_index ,
9711008 ** kwargs )
9721009
9731010 if isinstance (series , series_cls ):
@@ -990,6 +1027,7 @@ def from_geopandas(cls,
9901027 options_kwargs = None ,
9911028 chart_kwargs = None ,
9921029 series_in_rows = False ,
1030+ series_index = None ,
9931031 ** kwargs ):
9941032 """Create a :class:`Chart <highcharts_core.chart.Chart>` instance whose
9951033 data is populated from a `geopandas <https://geopandas.org/>`__
@@ -1051,6 +1089,14 @@ def from_geopandas(cls,
10511089 :obj:`False <python:False>`.
10521090 :type series_in_rows: :class:`bool <python:bool>`
10531091
1092+ :param series_index: If supplied, generate the chart with the series that
1093+ Highcharts for Python generated from ``df`` at the ``series_index`` position.
1094+ Defaults to :obj:`None <python:None>`, which includes all series generated
1095+ from ``df`` on the chart.
1096+
1097+ :type series_index: :class:`int <python:int>`, slice, or
1098+ :obj:`None <python:None>`
1099+
10541100 :param **kwargs: Additional keyword arguments that are - in turn - propagated to
10551101 the series created from the ``gdf``.
10561102
@@ -1063,19 +1109,40 @@ def from_geopandas(cls,
10631109 :raises HighchartsDependencyError: if `pandas <https://pandas.pydata.org/>`_ is
10641110 not available in the runtime environment
10651111 """
1066- chart_kwargs = validators .dict (chart_kwargs , allow_empty = True ) or {}
1112+ if not series_type :
1113+ raise errors .HighchartsValueError ('series_type cannot be empty' )
1114+ series_type = str (series_type ).lower ()
1115+
1116+ if not isinstance (options_kwargs , (dict , UserDict , type (None ))):
1117+ raise errors .HighchartsValueError (f'options_kwarts expects a dict. '
1118+ f'Received: { options_kwargs .__class__ .__name__ } ' )
1119+ if not options_kwargs :
1120+ options_kwargs = {}
1121+
1122+ if not isinstance (chart_kwargs , (dict , UserDict , type (None ))):
1123+ raise errors .HighchartsValueError (f'chart_kwargs expects a dict. '
1124+ f'Received: { chart_kwargs .__class__ .__name__ } ' )
1125+ if not chart_kwargs :
1126+ chart_kwargs = {}
1127+
1128+ if not isinstance (kwargs , (dict , UserDict , type (None ))):
1129+ raise errors .HighchartsValueError (f'kwargs expects a dict. '
1130+ f'Received: { kwargs .__class__ .__name__ } ' )
1131+ if not kwargs :
1132+ kwargs = {}
10671133
10681134 series_cls = SERIES_CLASSES .get (series_type , None )
10691135
10701136 if series_in_rows :
10711137 series = series_cls .from_pandas_in_rows (gdf ,
10721138 series_kwargs = series_kwargs ,
1073- options_kwargs = options_kwargs ,
1139+ series_index = series_index ,
10741140 ** kwargs )
10751141 else :
10761142 series = series_cls .from_pandas (gdf ,
10771143 property_map = property_map ,
10781144 series_kwargs = series_kwargs ,
1145+ series_index = series_index ,
10791146 ** kwargs )
10801147
10811148 if isinstance (series , series_cls ):
0 commit comments