Skip to content

Commit

Permalink
Fix repr when cols<=20 and rows>60 (#69)
Browse files Browse the repository at this point in the history
* Fix repr when cols<=20 and rows>60

* Fix whitespace
  • Loading branch information
frreiss authored and devin-petersohn committed Aug 9, 2018
1 parent 4311f97 commit 14240e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
11 changes: 5 additions & 6 deletions modin/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,18 +385,16 @@ def col_dots_builder(full_front, full_back):
if len(self.index) >= 60:
head_blocks = self._head_block_builder(30)
tail_blocks = self._tail_block_builder(30)
length_of_index = 30
index_of_head = self.index[:30]
index_of_tail = self.index[-30:]
else:
head_blocks = self._block_partitions
# We set this to None so we know
tail_blocks = None
length_of_index = len(self.index)
index_of_head = self.index

# Get first and last 10 columns if there are more than 20 columns
if len(self._col_metadata) >= 20:

index_of_head = self.index[:length_of_index]

# Building the front blocks from head_blocks
front_blocks = \
front_block_builder(head_blocks, 10, index_of_head)
Expand All @@ -410,7 +408,6 @@ def col_dots_builder(full_front, full_back):

# True only if we have >60 rows in the DataFrame
if tail_blocks is not None:
index_of_tail = self.index[-30:]
# Building the font blocks from tail_blocks
front_blocks = \
front_block_builder(tail_blocks, 10, index_of_tail)
Expand All @@ -435,6 +432,7 @@ def col_dots_builder(full_front, full_back):
]
full_head = pandas.concat(list_of_head_rows)
full_head.columns = self.columns
full_head.index = index_of_head

# True only if we have >60 rows in the DataFrame
if tail_blocks is not None:
Expand All @@ -444,6 +442,7 @@ def col_dots_builder(full_front, full_back):
for df in tail_blocks]
full_tail = pandas.concat(list_of_tail_rows)
full_tail.columns = self.columns
full_tail.index = index_of_tail

return row_dots_builder(full_head, full_tail)
else:
Expand Down
15 changes: 15 additions & 0 deletions modin/pandas/test/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3415,18 +3415,33 @@ def test___repr__():
#
# assert repr(pandas_df) == repr(ray_df)

# ___repr___ method has a different code path depending on
# whether the number of rows is >60; and a different code path
# depending on the number of columns is >20.
# Previous test cases already check the case when cols>20
# and rows>60. The cases that follow exercise the other three
# combinations.
# rows <= 60, cols > 20
frame_data = np.random.randint(0, 100, size=(10, 100))
pandas_df = pandas.DataFrame(frame_data)
ray_df = pd.DataFrame(frame_data)

assert repr(pandas_df) == repr(ray_df)

# rows <= 60, cols <= 20
frame_data = np.random.randint(0, 100, size=(10, 10))
pandas_df = pandas.DataFrame(frame_data)
ray_df = pd.DataFrame(frame_data)

assert repr(pandas_df) == repr(ray_df)

# rows > 60, cols <= 20
frame_data = np.random.randint(0, 100, size=(100, 10))
pandas_df = pandas.DataFrame(frame_data)
ray_df = pd.DataFrame(frame_data)

assert repr(pandas_df) == repr(ray_df)


@pytest.fixture
def test_loc(ray_df, pd_df):
Expand Down

0 comments on commit 14240e1

Please sign in to comment.