[SPARK-45130][CONNECT][ML][PYTHON] Avoid Spark connect ML model to change input pandas dataframe#42887
Closed
WeichenXu123 wants to merge 8 commits intoapache:masterfrom
Closed
Conversation
37 tasks
zhengruifeng
approved these changes
Sep 12, 2023
harupy
reviewed
Sep 12, 2023
harupy
reviewed
Sep 13, 2023
harupy
reviewed
Sep 13, 2023
harupy
reviewed
Sep 13, 2023
HyukjinKwon
reviewed
Sep 13, 2023
| import tempfile | ||
| import unittest | ||
| import numpy as np | ||
| import pandas as pd |
Member
There was a problem hiding this comment.
can you import this within test_binary_classes_logistic_regression or under should_test_connect so the tests can be skipped fine when pandas is not installed?
Contributor
Author
There was a problem hiding this comment.
isn't pandas always installed in CI image ?
HyukjinKwon
reviewed
Sep 13, 2023
| import os | ||
| import pickle | ||
| import numpy as np | ||
| import pandas as pd |
HyukjinKwon
reviewed
Sep 13, 2023
| import tempfile | ||
| import unittest | ||
| import numpy as np | ||
| import pandas as pd |
HyukjinKwon
approved these changes
Sep 18, 2023
Contributor
|
merged to master |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changes were proposed in this pull request?
Currently, to avoid data copy, Spark connect ML model directly changes input pandas dataframe for appending prediction columns. But we can use
pandas_df.copy(deep=False)to shallow copy it and then append prediction columns in copied dataframe. This is easier for user to use it.Why are the changes needed?
This makes
pyspark.ml.connectmodeltransformmethod has more similar behavior withpyspark.mlmodel, i.e., the input dataframe is intact aftertransformis called. Otherwise user might be surprise at the new behavior and have to change more code to migrate their workload topyspark.ml.connectDoes this PR introduce any user-facing change?
Yes.
Previous behavior:
In
pyspark.ml.connect,model.transformwill append new columns into input pandas dataframe, and return input dataframe object.Changed behavior:
In
pyspark.ml.connect,model.transformwill shallow copy input pandas dataframe and append new columns into shallow copied pandas dataframe, then return copied pandas dataframe.How was this patch tested?
Unit tests.
Was this patch authored or co-authored using generative AI tooling?
No.