-
Notifications
You must be signed in to change notification settings - Fork 653
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
FEAT-#2606: Support creating DataFrame from remote partitions #2613
Merged
vnlitvinov
merged 7 commits into
modin-project:master
from
YarShev:dev/yigoshev-issue2606
Jan 28, 2021
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0ec20aa
FEAT-#2606: Support creating DataFrame from remote partitions
YarShev 8f44cbf
FEAT-#2606: Use `factory` parameter instead of `engine`
YarShev b920435
FEAT-#2606: Remove `factory` parameter
YarShev 9e90602
FEAT-#2606: Add tests; Address comments
YarShev 49e0fb2
FEAT-#2606: Add suggested comments
YarShev b89f54c
FEAT-#2606: Move the functions to another location; Add comments
YarShev 954cbe4
FIX-#2606: Apply suggestion related to new location
YarShev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# Licensed to Modin Development Team under one or more contributor license agreements. | ||
# See the NOTICE file distributed with this work for additional information regarding | ||
# copyright ownership. The Modin Development Team licenses this file to you under the | ||
# Apache License, Version 2.0 (the "License"); you may not use this file except in | ||
# compliance with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under | ||
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
# ANY KIND, either express or implied. See the License for the specific language | ||
# governing permissions and limitations under the License. | ||
|
||
import numpy as np | ||
import pandas | ||
import pytest | ||
|
||
import modin.pandas as pd | ||
from modin.api import unwrap_partitions, create_df_from_partitions | ||
from modin.config import Engine, NPartitions | ||
from modin.pandas.test.utils import df_equals | ||
|
||
|
||
if Engine.get() == "Ray": | ||
import ray | ||
if Engine.get() == "Dask": | ||
from distributed.client import get_client | ||
|
||
NPartitions.put(4) | ||
|
||
|
||
@pytest.mark.parametrize("axis", [None, 0, 1]) | ||
def test_unwrap_partitions(axis): | ||
data = np.random.randint(0, 100, size=(2 ** 16, 2 ** 8)) | ||
df = pd.DataFrame(data) | ||
|
||
if axis is None: | ||
expected_partitions = df._query_compiler._modin_frame._partitions | ||
actual_partitions = np.array(unwrap_partitions(df, axis=axis)) | ||
assert ( | ||
expected_partitions.shape[0] == actual_partitions.shape[0] | ||
and expected_partitions.shape[1] == expected_partitions.shape[1] | ||
) | ||
for row_idx in range(expected_partitions.shape[0]): | ||
for col_idx in range(expected_partitions.shape[1]): | ||
if Engine.get() == "Ray": | ||
assert ( | ||
expected_partitions[row_idx][col_idx].oid | ||
== actual_partitions[row_idx][col_idx] | ||
) | ||
if Engine.get() == "Dask": | ||
assert ( | ||
expected_partitions[row_idx][col_idx].future | ||
== actual_partitions[row_idx][col_idx] | ||
) | ||
else: | ||
expected_axis_partitions = ( | ||
df._query_compiler._modin_frame._frame_mgr_cls.axis_partition( | ||
df._query_compiler._modin_frame._partitions, axis ^ 1 | ||
) | ||
) | ||
expected_axis_partitions = [ | ||
axis_partition.coalesce().unwrap(squeeze=True) | ||
for axis_partition in expected_axis_partitions | ||
] | ||
actual_axis_partitions = unwrap_partitions(df, axis=axis) | ||
assert len(expected_axis_partitions) == len(actual_axis_partitions) | ||
for item_idx in range(len(expected_axis_partitions)): | ||
if Engine.get() == "Ray": | ||
df_equals( | ||
ray.get(expected_axis_partitions[item_idx]), | ||
ray.get(actual_axis_partitions[item_idx]), | ||
) | ||
if Engine.get() == "Dask": | ||
df_equals( | ||
expected_axis_partitions[item_idx].result(), | ||
actual_axis_partitions[item_idx].result(), | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("axis", [None, 0, 1]) | ||
def test_create_df_from_partitions(axis): | ||
data = np.random.randint(0, 100, size=(2 ** 16, 2 ** 8)) | ||
df1, df2 = pandas.DataFrame(data), pandas.DataFrame(data) | ||
expected_df = pandas.concat([df1, df2], axis=1 if axis is None else axis) | ||
if Engine.get() == "Ray": | ||
if axis is None: | ||
futures = [[ray.put(df1), ray.put(df2)]] | ||
else: | ||
futures = [ray.put(df1), ray.put(df2)] | ||
if Engine.get() == "Dask": | ||
client = get_client() | ||
if axis is None: | ||
futures = [client.scatter([df1, df2], hash=False)] | ||
else: | ||
futures = client.scatter([df1, df2], hash=False) | ||
actual_df = create_df_from_partitions(futures, axis) | ||
df_equals(expected_df, actual_df) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this a bug in
_unwrap_partitions
? How is this change needed forcreate_df_from_partitions
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we hold all partitions as 2D np.array the
unwrap_partitions
now returns 2D list instead of 1D list when passed axis isNone
. It is that what I described at the top of the PR. This change is needed forcreate_df_from_partitions
to create df from 2D list of partitions when passed axis isNone
.