1414import itertools
1515import sys
1616from textwrap import dedent
17- from typing import FrozenSet , List , Optional , Set , Tuple , Type , Union
17+ from typing import FrozenSet , List , Optional , Sequence , Set , Tuple , Type , Union
1818import warnings
1919
2020import numpy as np
7979)
8080from pandas .core .dtypes .missing import isna , notna
8181
82- from pandas ._typing import Axes , Dtype
82+ from pandas ._typing import Axes , Dtype , FilePathOrBuffer
8383from pandas .core import algorithms , common as com , nanops , ops
8484from pandas .core .accessor import CachedAccessor
8585from pandas .core .arrays import Categorical , ExtensionArray
@@ -558,14 +558,14 @@ def _is_homogeneous_type(self) -> bool:
558558 # ----------------------------------------------------------------------
559559 # Rendering Methods
560560
561- def _repr_fits_vertical_ (self ):
561+ def _repr_fits_vertical_ (self ) -> bool :
562562 """
563563 Check length against max_rows.
564564 """
565565 max_rows = get_option ("display.max_rows" )
566566 return len (self ) <= max_rows
567567
568- def _repr_fits_horizontal_ (self , ignore_width = False ):
568+ def _repr_fits_horizontal_ (self , ignore_width : bool = False ) -> bool :
569569 """
570570 Check if full repr fits in horizontal boundaries imposed by the display
571571 options width and max_columns.
@@ -619,7 +619,7 @@ def _repr_fits_horizontal_(self, ignore_width=False):
619619
620620 return repr_width < width
621621
622- def _info_repr (self ):
622+ def _info_repr (self ) -> bool :
623623 """
624624 True if the repr should show the info view.
625625 """
@@ -628,7 +628,7 @@ def _info_repr(self):
628628 self ._repr_fits_horizontal_ () and self ._repr_fits_vertical_ ()
629629 )
630630
631- def __repr__ (self ):
631+ def __repr__ (self ) -> str :
632632 """
633633 Return a string representation for a particular DataFrame.
634634 """
@@ -658,7 +658,7 @@ def __repr__(self):
658658
659659 return buf .getvalue ()
660660
661- def _repr_html_ (self ):
661+ def _repr_html_ (self ) -> Optional [ str ] :
662662 """
663663 Return a html representation for a particular DataFrame.
664664
@@ -705,6 +705,7 @@ def _repr_html_(self):
705705 return None
706706
707707 @Substitution (
708+ header_type = "bool or sequence" ,
708709 header = "Write out the column names. If a list of strings "
709710 "is given, it is assumed to be aliases for the "
710711 "column names" ,
@@ -714,25 +715,25 @@ def _repr_html_(self):
714715 @Substitution (shared_params = fmt .common_docstring , returns = fmt .return_docstring )
715716 def to_string (
716717 self ,
717- buf = None ,
718- columns = None ,
719- col_space = None ,
720- header = True ,
721- index = True ,
722- na_rep = "NaN" ,
723- formatters = None ,
724- float_format = None ,
725- sparsify = None ,
726- index_names = True ,
727- justify = None ,
728- max_rows = None ,
729- min_rows = None ,
730- max_cols = None ,
731- show_dimensions = False ,
732- decimal = "." ,
733- line_width = None ,
734- max_colwidth = None ,
735- ):
718+ buf : Optional [ FilePathOrBuffer [ str ]] = None ,
719+ columns : Optional [ Sequence [ str ]] = None ,
720+ col_space : Optional [ int ] = None ,
721+ header : Union [ bool , Sequence [ str ]] = True ,
722+ index : bool = True ,
723+ na_rep : str = "NaN" ,
724+ formatters : Optional [ fmt . formatters_type ] = None ,
725+ float_format : Optional [ fmt . float_format_type ] = None ,
726+ sparsify : Optional [ bool ] = None ,
727+ index_names : bool = True ,
728+ justify : Optional [ str ] = None ,
729+ max_rows : Optional [ int ] = None ,
730+ min_rows : Optional [ int ] = None ,
731+ max_cols : Optional [ int ] = None ,
732+ show_dimensions : bool = False ,
733+ decimal : str = "." ,
734+ line_width : Optional [ int ] = None ,
735+ max_colwidth : Optional [ int ] = None ,
736+ ) -> Optional [ str ] :
736737 """
737738 Render a DataFrame to a console-friendly tabular output.
738739 %(shared_params)s
@@ -2162,6 +2163,7 @@ def to_parquet(
21622163 )
21632164
21642165 @Substitution (
2166+ header_type = "bool" ,
21652167 header = "Whether to print column labels, default True" ,
21662168 col_space_type = "str or int" ,
21672169 col_space = "The minimum width of each column in CSS length "
0 commit comments