Skip to content

Commit

Permalink
PERF-#0000: don't materialize axes when calling 'to_numpy'
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoly Myachev <[email protected]>
  • Loading branch information
anmyachev committed Nov 3, 2023
1 parent 7a9415e commit 4912262
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 9 additions & 1 deletion modin/core/dataframe/pandas/dataframe/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4055,6 +4055,7 @@ def to_pandas(self):

return df

@lazy_metadata_decorator(apply_axis="both")
def to_numpy(self, **kwargs):
"""
Convert this Modin DataFrame to a NumPy array.
Expand All @@ -4068,7 +4069,14 @@ def to_numpy(self, **kwargs):
-------
np.ndarray
"""
return self._partition_mgr_cls.to_numpy(self._partitions, **kwargs)
arr = self._partition_mgr_cls.to_numpy(self._partitions, **kwargs)
ErrorMessage.catch_bugs_and_request_email(
self.has_materialized_index
and len(arr) != len(self.index)
or self.has_materialized_columns
and len(arr[0]) != len(self.columns)
)
return arr

@lazy_metadata_decorator(apply_axis=None, transpose=True)
def transpose(self):
Expand Down
6 changes: 1 addition & 5 deletions modin/core/storage_formats/pandas/query_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,7 @@ def free(self):

# To NumPy
def to_numpy(self, **kwargs):
arr = self._modin_frame.to_numpy(**kwargs)
ErrorMessage.catch_bugs_and_request_email(
len(arr) != len(self.index) or len(arr[0]) != len(self.columns)
)
return arr
return self._modin_frame.to_numpy(**kwargs)

# END To NumPy

Expand Down

0 comments on commit 4912262

Please sign in to comment.