@@ -135,7 +135,7 @@ def init_notebook_mode(
135135 all_interactive : bool = True ,
136136 connected : bool = GOOGLE_COLAB ,
137137 dt_bundle : Optional [Union [Path , str ]] = None ,
138- ):
138+ ) -> None :
139139 """Load the DataTables library and the corresponding css (if connected=False),
140140 and (if all_interactive=True), activate the DataTables representation for all the Pandas DataFrames and Series.
141141
@@ -189,7 +189,8 @@ def init_notebook_mode(
189189 display (HTML (generate_init_offline_itables_html (dt_bundle )))
190190
191191
192- def get_animated_logo (display_logo_when_loading ):
192+ def get_animated_logo (display_logo_when_loading : bool ) -> str :
193+ """Return the HTML for the loading logo of ITables"""
193194 if not display_logo_when_loading :
194195 return ""
195196 return f"<a href=https://mwouts.github.io/itables/>{ read_package_file ('logo/loading.svg' )} </a>"
@@ -265,15 +266,15 @@ def _flat_header(df, show_index):
265266 return header
266267
267268
268- def _tfoot_from_thead (thead ) :
269+ def _tfoot_from_thead (thead : str ) -> str :
269270 header_rows = thead .split ("</tr>" )
270271 last_row = header_rows [- 1 ]
271272 assert not last_row .strip (), last_row
272273 header_rows = header_rows [:- 1 ]
273274 return "" .join (row + "</tr>" for row in header_rows [::- 1 ] if "<tr" in row ) + "\n "
274275
275276
276- def get_keys_to_be_evaluated (data ) -> list [list [Union [int , str ]]]:
277+ def get_keys_to_be_evaluated (data : Any ) -> list [list [Union [int , str ]]]:
277278 """
278279 This function returns the keys that need to be evaluated
279280 in the ITable arguments
@@ -296,7 +297,7 @@ def get_keys_to_be_evaluated(data) -> list[list[Union[int, str]]]:
296297 return keys_to_be_evaluated
297298
298299
299- def replace_value (template , pattern , value ) :
300+ def replace_value (template : str , pattern : str , value : str ) -> str :
300301 """Set the given pattern to the desired value in the template,
301302 after making sure that the pattern is found exactly once."""
302303 count = template .count (pattern )
@@ -311,15 +312,15 @@ def replace_value(template, pattern, value):
311312 return template .replace (pattern , value )
312313
313314
314- def _datatables_repr_ (df ) :
315+ def _datatables_repr_ (df : DataFrameOrSeries ) -> str :
315316 return to_html_datatable (df , connected = _CONNECTED )
316317
317318
318319def to_html_datatable (
319320 df : DataFrameOrSeries ,
320321 caption : Optional [str ] = None ,
321322 ** kwargs : Unpack [ITableOptions ],
322- ):
323+ ) -> str :
323324 """
324325 Return the HTML representation of the given
325326 dataframe as an interactive datatable
@@ -548,8 +549,14 @@ def get_itables_extension_arguments(
548549
549550
550551def warn_if_selected_rows_are_not_visible (
551- selected_rows , full_row_count , data_row_count , warn_on_selected_rows_not_rendered
552- ):
552+ selected_rows : Optional [Sequence [int ]],
553+ full_row_count : int ,
554+ data_row_count : int ,
555+ warn_on_selected_rows_not_rendered : bool ,
556+ ) -> Sequence [int ]:
557+ """
558+ Issue a warning if the selected rows are not within the range of rendered rows.
559+ """
553560 if selected_rows is None :
554561 return []
555562
@@ -589,7 +596,11 @@ def warn_if_selected_rows_are_not_visible(
589596 return [i for i in selected_rows if i < bottom_limit or i >= top_limit ]
590597
591598
592- def check_table_id (table_id : Optional [str ], kwargs , df = None ) -> str :
599+ def check_table_id (
600+ table_id : Optional [str ],
601+ kwargs : Union [ITableOptions , DTForITablesOptions ],
602+ df : Optional [DataFrameOrSeries ] = None ,
603+ ) -> str :
593604 """Make sure that the table_id is a valid HTML id.
594605
595606 See also https://stackoverflow.com/questions/70579/html-valid-id-attribute-values
@@ -614,7 +625,9 @@ def check_table_id(table_id: Optional[str], kwargs, df=None) -> str:
614625 return table_id
615626
616627
617- def set_default_options (kwargs : ITableOptions , * , use_to_html : bool , app_mode : bool ):
628+ def set_default_options (
629+ kwargs : ITableOptions , * , use_to_html : bool , app_mode : bool
630+ ) -> None :
618631 if not app_mode :
619632 kwargs ["connected" ] = kwargs .get (
620633 "connected" , ("dt_url" in kwargs ) or _CONNECTED
@@ -681,7 +694,7 @@ def html_table_from_template(
681694 connected : bool ,
682695 display_logo_when_loading : bool ,
683696 kwargs : DTForITablesOptions ,
684- ):
697+ ) -> str :
685698 if "css" in kwargs :
686699 raise TypeError (
687700 "The 'css' argument has been deprecated, see the new "
@@ -800,7 +813,7 @@ def _filter_control(control, downsampling_warning):
800813 return None
801814
802815
803- def safe_reset_index (df ) :
816+ def safe_reset_index (df : pd . DataFrame ) -> pd . DataFrame :
804817 try :
805818 return df .reset_index ()
806819 except ValueError :
@@ -825,6 +838,6 @@ def show(
825838 df : DataFrameOrSeries ,
826839 caption : Optional [str ] = None ,
827840 ** kwargs : Unpack [ITableOptions ],
828- ):
841+ ) -> None :
829842 """Render the given dataframe as an interactive datatable"""
830843 display (HTML (to_html_datatable (df , caption , ** kwargs )))
0 commit comments