85
85
common_docstring = """
86
86
Parameters
87
87
----------
88
- buf : StringIO-like, optional
89
- Buffer to write to.
88
+ buf : str, Path or StringIO-like, optional, default None
89
+ Buffer to write to. If None, the output is returned as a string.
90
90
columns : sequence, optional, default None
91
91
The subset of columns to write. Writes all columns by default.
92
92
col_space : %(col_space_type)s, optional
156
156
return_docstring = """
157
157
Returns
158
158
-------
159
- str (or unicode, depending on data and options)
160
- String representation of the dataframe.
159
+ str or None
160
+ If buf is None, returns the result as a string. Otherwise returns
161
+ None.
161
162
"""
162
163
163
164
@@ -471,6 +472,10 @@ def _get_formatter(self, i: Union[str, int]) -> Optional[Callable]:
471
472
def get_buffer (
472
473
self , buf : Optional [FilePathOrBuffer [str ]], encoding : Optional [str ] = None
473
474
):
475
+ """
476
+ Context manager to open, yield and close buffer for filenames or Path-like
477
+ objects, otherwise yield buf unchanged.
478
+ """
474
479
if buf is not None :
475
480
buf = _stringify_path (buf )
476
481
else :
@@ -488,13 +493,19 @@ def get_buffer(
488
493
raise TypeError ("buf is not a file name and it has no write method" )
489
494
490
495
def write_result (self , buf : IO [str ]) -> None :
496
+ """
497
+ Write the result of serialization to buf.
498
+ """
491
499
raise AbstractMethodError (self )
492
500
493
501
def get_result (
494
502
self ,
495
503
buf : Optional [FilePathOrBuffer [str ]] = None ,
496
504
encoding : Optional [str ] = None ,
497
505
) -> Optional [str ]:
506
+ """
507
+ Perform serialization. Write to buf or return as string if buf is None.
508
+ """
498
509
with self .get_buffer (buf , encoding = encoding ) as f :
499
510
self .write_result (buf = f )
500
511
if buf is None :
0 commit comments