14
14
import itertools
15
15
import sys
16
16
from 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
18
18
import warnings
19
19
20
20
import numpy as np
79
79
)
80
80
from pandas .core .dtypes .missing import isna , notna
81
81
82
- from pandas ._typing import Axes , Dtype
82
+ from pandas ._typing import Axes , Dtype , FilePathOrBuffer
83
83
from pandas .core import algorithms , common as com , nanops , ops
84
84
from pandas .core .accessor import CachedAccessor
85
85
from pandas .core .arrays import Categorical , ExtensionArray
@@ -558,14 +558,14 @@ def _is_homogeneous_type(self) -> bool:
558
558
# ----------------------------------------------------------------------
559
559
# Rendering Methods
560
560
561
- def _repr_fits_vertical_ (self ):
561
+ def _repr_fits_vertical_ (self ) -> bool :
562
562
"""
563
563
Check length against max_rows.
564
564
"""
565
565
max_rows = get_option ("display.max_rows" )
566
566
return len (self ) <= max_rows
567
567
568
- def _repr_fits_horizontal_ (self , ignore_width = False ):
568
+ def _repr_fits_horizontal_ (self , ignore_width : bool = False ) -> bool :
569
569
"""
570
570
Check if full repr fits in horizontal boundaries imposed by the display
571
571
options width and max_columns.
@@ -619,7 +619,7 @@ def _repr_fits_horizontal_(self, ignore_width=False):
619
619
620
620
return repr_width < width
621
621
622
- def _info_repr (self ):
622
+ def _info_repr (self ) -> bool :
623
623
"""
624
624
True if the repr should show the info view.
625
625
"""
@@ -628,7 +628,7 @@ def _info_repr(self):
628
628
self ._repr_fits_horizontal_ () and self ._repr_fits_vertical_ ()
629
629
)
630
630
631
- def __repr__ (self ):
631
+ def __repr__ (self ) -> str :
632
632
"""
633
633
Return a string representation for a particular DataFrame.
634
634
"""
@@ -658,7 +658,7 @@ def __repr__(self):
658
658
659
659
return buf .getvalue ()
660
660
661
- def _repr_html_ (self ):
661
+ def _repr_html_ (self ) -> Optional [ str ] :
662
662
"""
663
663
Return a html representation for a particular DataFrame.
664
664
@@ -705,6 +705,7 @@ def _repr_html_(self):
705
705
return None
706
706
707
707
@Substitution (
708
+ header_type = "bool or sequence" ,
708
709
header = "Write out the column names. If a list of strings "
709
710
"is given, it is assumed to be aliases for the "
710
711
"column names" ,
@@ -714,25 +715,25 @@ def _repr_html_(self):
714
715
@Substitution (shared_params = fmt .common_docstring , returns = fmt .return_docstring )
715
716
def to_string (
716
717
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 ] :
736
737
"""
737
738
Render a DataFrame to a console-friendly tabular output.
738
739
%(shared_params)s
@@ -2162,6 +2163,7 @@ def to_parquet(
2162
2163
)
2163
2164
2164
2165
@Substitution (
2166
+ header_type = "bool" ,
2165
2167
header = "Whether to print column labels, default True" ,
2166
2168
col_space_type = "str or int" ,
2167
2169
col_space = "The minimum width of each column in CSS length "
0 commit comments