Skip to content

Commit

Permalink
Support console with __repr__ like pandas (#984)
Browse files Browse the repository at this point in the history
* Support console with __repr__ like pandas

* Resolves #898
* Pre-compute the number of columns based on the width of the column
  names
  * This guarantees that we will get at least as many columns from the
    partitions as we need.
  * Compute width using pandas utility to match the behavior
* Tested locally to verify behavior
  • Loading branch information
devin-petersohn authored Jan 12, 2020
1 parent c36592d commit 7874281
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions modin/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,28 @@ def __init__(
self._query_compiler = query_compiler

def __repr__(self):
num_rows = pandas.get_option("max_rows") or 10
num_cols = pandas.get_option("max_columns") or 20
from pandas.io.formats import console

num_rows = pandas.get_option("display.max_rows") or 10
num_cols = pandas.get_option("display.max_columns") or 20
if pandas.get_option("display.max_columns") is None and pandas.get_option(
"display.expand_frame_repr"
):
width, _ = console.get_console_size()
col_counter = 0
i = 0
while col_counter < width:
col_counter += len(str(self.columns[i])) + 1
i += 1

num_cols = i
i = len(self.columns) - 1
col_counter = 0
while col_counter < width:
col_counter += len(str(self.columns[i])) + 1
i -= 1

num_cols += len(self.columns) - i
result = repr(self._build_repr_df(num_rows, num_cols))
if len(self.index) > num_rows or len(self.columns) > num_cols:
# The split here is so that we don't repr pandas row lengths.
Expand Down

0 comments on commit 7874281

Please sign in to comment.