Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

- Added support for dict values in `Series.str.get`, `Series.str.slice`, and `Series.str.__getitem__` (`Series.str[...]`).
- Added support for `DataFrame.to_html`.
- Added support for `DataFrame.to_string` and `Series.to_string`.

#### Improvements

Expand Down
4 changes: 3 additions & 1 deletion docs/source/modin/dataframe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,6 @@ DataFrame
:toctree: pandas_api/

DataFrame.to_csv
DataFrame.to_html
DataFrame.to_html
DataFrame.to_string

1 change: 1 addition & 0 deletions docs/source/modin/series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,4 @@ Series
:toctree: pandas_api/

Series.to_csv
Series.to_string
2 changes: 1 addition & 1 deletion docs/source/modin/supported/dataframe_supported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ Methods
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``to_stata`` | N | | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``to_string`` | N | | |
| ``to_string`` | Y | | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``to_timestamp`` | N | | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
Expand Down
2 changes: 1 addition & 1 deletion docs/source/modin/supported/series_supported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ Methods
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``to_sql`` | N | | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``to_string`` | N | | |
| ``to_string`` | Y | | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
| ``to_timestamp`` | N | | |
+-----------------------------+---------------------------------+----------------------------------+----------------------------------------------------+
Expand Down
95 changes: 95 additions & 0 deletions src/snowflake/snowpark/modin/plugin/docstrings/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4339,6 +4339,101 @@ def to_records():
Convert ``DataFrame`` to a NumPy record array.
"""

def to_string():
"""
Render a DataFrame to a console-friendly tabular output.

Parameters
----------
buf : str, Path or StringIO-like, optional, default None
Buffer to write to. If None, the output is returned as a string.

columns : array-like, optional, default None
The subset of columns to write. Writes all columns by default.

col_space : int, list or dict of int, optional
The minimum width of each column. If a list of ints is given every integers corresponds with one column. If a dict is given, the key references the column, while the value defines the space to use..

header : bool or list of str, optional
Write out the column names. If a list of columns is given, it is assumed to be aliases for the column names.

index : bool, optional, default True
Whether to print index (row) labels.

na_rep : str, optional, default ‘NaN’
String representation of NaN to use.

formatters : list, tuple or dict of one-param. functions, optional
Formatter functions to apply to columns’ elements by position or name. The result of each function must be a unicode string. List/tuple must be of length equal to the number of columns.

float_format : one-parameter function, optional, default None
Formatter function to apply to columns’ elements if they are floats. This function must return a unicode string and will be applied only to the non-NaN elements, with NaN being handled by na_rep.

sparsify : bool, optional, default True
Set to False for a DataFrame with a hierarchical index to print every multiindex key at each row.

index_names : bool, optional, default True
Prints the names of the indexes.

justify : str, default None
How to justify the column labels. If None uses the option from the print configuration (controlled by set_option), ‘right’ out of the box. Valid values are
- left
- right
- center
- justify
- justify-all
- start
- end
- inherit
- match-parent
- initial
- unset.

max_rows : int, optional
Maximum number of rows to display in the console.

max_cols : int, optional
Maximum number of columns to display in the console.

show_dimensions : bool, default False
Display DataFrame dimensions (number of rows by number of columns).

decimal : str, default ‘.’
Character recognized as decimal separator, e.g. ‘,’ in Europe.

line_width : int, optional
Width to wrap a line in characters.

min_rows : int, optional
The number of rows to display in the console in a truncated repr (when number of rows is above max_rows).

max_colwidth : int, optional
Max width to truncate each column in characters. By default, no limit.

encoding : str, default “utf-8”
Set character encoding.

Returns
-------
str or None
If buf is None, returns the result as a string. Otherwise returns None.

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
"""

def to_stata():
pass

Expand Down
43 changes: 43 additions & 0 deletions src/snowflake/snowpark/modin/plugin/docstrings/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3603,6 +3603,49 @@ def to_period():
def to_string():
"""
Render a string representation of the Series.

Parameters
----------
buf : StringIO-like, optional
Buffer to write to.

na_rep : str, optional
String representation of NaN to use, default ‘NaN’.

float_format : one-parameter function, optional
Formatter function to apply to columns’ elements if they are floats, default None.

header : bool, default True
Add the Series header (index name).

index : bool, optional
Add index (row) labels, default True.

length : bool, default False
Add the Series length.

dtype : bool, default False
Add the Series dtype.

name : bool, default False
Add the Series name if not None.

max_rows : int, optional
Maximum number of rows to show before truncating. If None, show all.

min_rows : int, optional
The number of rows to display in a truncated repr (when number of rows is above max_rows).

Returns
-------
str or None
String representation of Series if buf=None, otherwise None.

Examples
--------
>>> ser = pd.Series([1, 2, 3]).to_string()
>>> ser
'0 1\\n1 2\\n2 3'
"""

def to_timestamp():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,32 +411,6 @@ def to_pickle(
pass # pragma: no cover


@register_base_not_implemented()
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,
min_rows=None,
max_cols=None,
show_dimensions=False,
decimal=".",
line_width=None,
max_colwidth=None,
encoding=None,
): # noqa: PR01, RT01, D200
pass # pragma: no cover


@register_base_not_implemented()
def to_sql(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,54 @@ def to_records(
pass # pragma: no cover


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,
min_rows=None,
max_cols=None,
show_dimensions=False,
decimal=".",
line_width=None,
max_colwidth=None,
encoding=None,
): # noqa: PR01, RT01, D200
WarningMessage.single_warning(
"DataFrame.to_string materializes data to the local machine."
)
return self._to_pandas().to_string(
buf=buf,
columns=columns,
col_space=col_space,
header=header,
index=index,
na_rep=na_rep,
formatters=formatters,
float_format=float_format,
sparsify=sparsify,
index_names=index_names,
justify=justify,
max_rows=max_rows,
min_rows=min_rows,
max_cols=max_cols,
show_dimensions=show_dimensions,
decimal=decimal,
line_width=line_width,
max_colwidth=max_colwidth,
encoding=encoding,
)


@register_dataframe_not_implemented()
def to_stata(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ def to_period(self, freq=None, copy=True): # noqa: PR01, RT01, D200
pass # pragma: no cover


@register_series_not_implemented()
def to_string(
self,
buf=None,
Expand All @@ -349,7 +348,21 @@ def to_string(
max_rows=None,
min_rows=None,
): # noqa: PR01, RT01, D200
pass # pragma: no cover
WarningMessage.single_warning(
"Series.to_string materializes data to the local machine."
)
return self._to_pandas().to_string(
buf=buf,
na_rep=na_rep,
float_format=float_format,
header=header,
index=index,
length=length,
dtype=dtype,
name=name,
max_rows=max_rows,
min_rows=min_rows,
)


@register_series_not_implemented()
Expand Down
16 changes: 16 additions & 0 deletions tests/integ/modin/frame/test_to_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (c) 2012-2025 Snowflake Computing Inc. All rights reserved.
#

import modin.pandas as pd
import pandas as native_pd

import snowflake.snowpark.modin.plugin # noqa: F401
from tests.integ.utils.sql_counter import sql_count_checker


@sql_count_checker(query_count=2)
def test_to_string():
native_df = native_pd.DataFrame(data={"col1": [1, 2], "col2": [4, 3]})
snow_df = pd.DataFrame(native_df)
assert snow_df.to_string() == native_df.to_string()
16 changes: 16 additions & 0 deletions tests/integ/modin/series/test_to_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Copyright (c) 2012-2025 Snowflake Computing Inc. All rights reserved.
#

import modin.pandas as pd
import pandas as native_pd

import snowflake.snowpark.modin.plugin # noqa: F401
from tests.integ.utils.sql_counter import sql_count_checker


@sql_count_checker(query_count=2)
def test_to_string():
native_ser = native_pd.Series([-1, 5, 6, 2, 4])
snow_ser = pd.Series(native_ser)
assert snow_ser.to_string() == native_ser.to_string()
2 changes: 0 additions & 2 deletions tests/unit/modin/test_unsupported.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def test_unsupported_general(general_method, kwargs):
["to_records", {}],
["to_sql", {"name": "", "con": ""}],
["to_stata", {"path": ""}],
["to_string", {}],
["to_timestamp", {}],
["to_xarray", {}],
["to_xml", {}],
Expand Down Expand Up @@ -174,7 +173,6 @@ def test_unsupported_df(df_method, kwargs):
["to_period", {}],
["to_pickle", {"path": ""}],
["to_sql", {"name": "", "con": ""}],
["to_string", {}],
["to_timestamp", {}],
["to_xarray", {}],
["transform", {"func": ""}],
Expand Down
Loading