-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-24976][PYTHON] Allow None for Decimal type conversion (specific to PyArrow 0.9.0) #21928
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
Closed
Closed
Changes from all commits
Commits
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,9 +216,10 @@ def _create_batch(series, timezone): | |
| :param timezone: A timezone to respect when handling timestamp values | ||
| :return: Arrow RecordBatch | ||
| """ | ||
|
|
||
| from pyspark.sql.types import _check_series_convert_timestamps_internal | ||
| import decimal | ||
| from distutils.version import LooseVersion | ||
| import pyarrow as pa | ||
| from pyspark.sql.types import _check_series_convert_timestamps_internal | ||
| # Make input conform to [(series1, type1), (series2, type2), ...] | ||
| if not isinstance(series, (list, tuple)) or \ | ||
| (len(series) == 2 and isinstance(series[1], pa.DataType)): | ||
|
|
@@ -236,6 +237,11 @@ def create_array(s, t): | |
| # TODO: need decode before converting to Arrow in Python 2 | ||
| return pa.Array.from_pandas(s.apply( | ||
| lambda v: v.decode("utf-8") if isinstance(v, str) else v), mask=mask, type=t) | ||
| elif t is not None and pa.types.is_decimal(t) and \ | ||
| LooseVersion("0.9.0") <= LooseVersion(pa.__version__) < LooseVersion("0.10.0"): | ||
| # TODO: see ARROW-2432. Remove when the minimum PyArrow version becomes 0.10.0. | ||
| return pa.Array.from_pandas(s.apply( | ||
| lambda v: decimal.Decimal('NaN') if v is None else v), mask=mask, type=t) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add test?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. existing test should test this |
||
| return pa.Array.from_pandas(s, mask=mask, type=t) | ||
|
|
||
| arrs = [create_array(s, t) for s, t in series] | ||
|
|
||
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.
consider a single place to check pyarrow versions?
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.
Yea, but not sure if I am aware of other issues specific to PyArrow versions. Will make a single place if I happen to fix things specific to PyArrow versions for sure.