@@ -489,6 +489,8 @@ def get_dataframe_repr_params() -> dict[str, Any]:
489
489
Supplying these parameters to DataFrame.to_string is equivalent to calling
490
490
``repr(DataFrame)``. This is useful if you want to adjust the repr output.
491
491
492
+ .. versionadded:: 1.4.0
493
+
492
494
Example
493
495
-------
494
496
>>> import pandas as pd
@@ -514,6 +516,44 @@ def get_dataframe_repr_params() -> dict[str, Any]:
514
516
}
515
517
516
518
519
+ def get_series_repr_params (series : Series ) -> dict [str , Any ]:
520
+ """Get the parameters used to repr(Series) calls using Series.to_string.
521
+
522
+ Supplying these parameters to Series.to_string is equivalent to calling
523
+ ``repr(series)``. This is useful if you want to adjust the series repr output.
524
+
525
+ .. versionadded:: 1.4.0
526
+
527
+ Example
528
+ -------
529
+ >>> import pandas as pd
530
+ >>>
531
+ >>> ser = pd.Series([1, 2, 3, 4])
532
+ >>> repr_params = pd.io.formats.format.get_series_repr_params(ser)
533
+ >>> repr(ser) == ser.to_string(**repr_params)
534
+ True
535
+ """
536
+ width , height = get_terminal_size ()
537
+ max_rows = (
538
+ height
539
+ if get_option ("display.max_rows" ) == 0
540
+ else get_option ("display.max_rows" )
541
+ )
542
+ min_rows = (
543
+ height
544
+ if get_option ("display.max_rows" ) == 0
545
+ else get_option ("display.min_rows" )
546
+ )
547
+
548
+ return {
549
+ "name" : series .name ,
550
+ "dtype" : series .dtype ,
551
+ "min_rows" : min_rows ,
552
+ "max_rows" : max_rows ,
553
+ "length" : get_option ("display.show_dimensions" ),
554
+ }
555
+
556
+
517
557
class DataFrameFormatter :
518
558
"""Class for processing dataframe formatting options and data."""
519
559
0 commit comments