Skip to content

Collect methods in generic/frame/series by purpose #23973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 61 additions & 49 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ def _constructor_expanddim(self):
from pandas.core.panel import Panel
return Panel

# ----------------------------------------------------------------------
# Constructors

def __init__(self, data=None, index=None, columns=None, dtype=None,
copy=False):
if data is None:
Expand Down Expand Up @@ -575,6 +578,8 @@ def _get_axes(N, K, index=index, columns=columns):

return create_block_manager_from_blocks([values], [columns, index])

# ----------------------------------------------------------------------

@property
def axes(self):
"""
Expand Down Expand Up @@ -643,6 +648,9 @@ def _is_homogeneous_type(self):
else:
return not self._data.is_mixed_type

# ----------------------------------------------------------------------
# Rendering Methods

def _repr_fits_vertical_(self):
"""
Check length against max_rows.
Expand Down Expand Up @@ -770,6 +778,57 @@ def _repr_html_(self):
else:
return None

@Substitution(header='Write out the column names. If a list of strings '
'is given, it is assumed to be aliases for the '
'column names')
@Substitution(shared_params=fmt.common_docstring,
returns=fmt.return_docstring)
def to_string(self, buf=None, columns=None, col_space=None, header=True,
index=True, na_rep='NaN', formatters=None, float_format=None,
sparsify=None, index_names=True, justify=None,
max_rows=None, max_cols=None, show_dimensions=False,
decimal='.', line_width=None):
"""
Render a DataFrame to a console-friendly tabular output.
%(shared_params)s
line_width : int, optional
Width to wrap a line in characters.
%(returns)s
See Also
--------
to_html : Convert DataFrame to HTML.

Examples
--------
>>> d = {'col1': [1, 2, 3], 'col2': [4, 5, 6]}
>>> df = pd.DataFrame(d)
>>> print(df.to_string())
col1 col2
0 1 4
1 2 5
2 3 6
"""

formatter = fmt.DataFrameFormatter(self, buf=buf, columns=columns,
col_space=col_space, na_rep=na_rep,
formatters=formatters,
float_format=float_format,
sparsify=sparsify, justify=justify,
index_names=index_names,
header=header, index=index,
max_rows=max_rows,
max_cols=max_cols,
show_dimensions=show_dimensions,
decimal=decimal,
line_width=line_width)
formatter.to_string()

if buf is None:
result = formatter.buf.getvalue()
return result

# ----------------------------------------------------------------------

@property
def style(self):
"""
Expand Down Expand Up @@ -2051,55 +2110,6 @@ def to_parquet(self, fname, engine='auto', compression='snappy',
compression=compression, index=index,
partition_cols=partition_cols, **kwargs)

@Substitution(header='Write out the column names. If a list of strings '
'is given, it is assumed to be aliases for the '
'column names')
@Substitution(shared_params=fmt.common_docstring,
returns=fmt.return_docstring)
def to_string(self, buf=None, columns=None, col_space=None, header=True,
index=True, na_rep='NaN', formatters=None, float_format=None,
sparsify=None, index_names=True, justify=None,
max_rows=None, max_cols=None, show_dimensions=False,
decimal='.', line_width=None):
"""
Render a DataFrame to a console-friendly tabular output.
%(shared_params)s
line_width : int, optional
Width to wrap a line in characters.
%(returns)s
See Also
--------
to_html : Convert DataFrame to HTML.

Examples
--------
>>> d = {'col1': [1, 2, 3], 'col2': [4, 5, 6]}
>>> df = pd.DataFrame(d)
>>> print(df.to_string())
col1 col2
0 1 4
1 2 5
2 3 6
"""

formatter = fmt.DataFrameFormatter(self, buf=buf, columns=columns,
col_space=col_space, na_rep=na_rep,
formatters=formatters,
float_format=float_format,
sparsify=sparsify, justify=justify,
index_names=index_names,
header=header, index=index,
max_rows=max_rows,
max_cols=max_cols,
show_dimensions=show_dimensions,
decimal=decimal,
line_width=line_width)
formatter.to_string()

if buf is None:
result = formatter.buf.getvalue()
return result

@Substitution(header='Whether to print column labels, default True')
@Substitution(shared_params=fmt.common_docstring,
returns=fmt.return_docstring)
Expand Down Expand Up @@ -2158,6 +2168,8 @@ def to_html(self, buf=None, columns=None, col_space=None, header=True,
if buf is None:
return formatter.buf.getvalue()

# ----------------------------------------------------------------------

def info(self, verbose=None, buf=None, max_cols=None, memory_usage=None,
null_counts=None):
"""
Expand Down
Loading