You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/01/07 10:39:49 UTC
[GitHub] asfgit closed pull request #23484: [SPARK-26559][ML][PySpark] ML
image can't work with numpy versions prior to 1.9
asfgit closed pull request #23484: [SPARK-26559][ML][PySpark] ML image can't work with numpy versions prior to 1.9
URL: https://github.com/apache/spark/pull/23484
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/python/pyspark/ml/image.py b/python/pyspark/ml/image.py
index edb90a3578546..a1aacea88e42e 100644
--- a/python/pyspark/ml/image.py
+++ b/python/pyspark/ml/image.py
@@ -28,6 +28,7 @@
import warnings
import numpy as np
+from distutils.version import LooseVersion
from pyspark import SparkContext
from pyspark.sql.types import Row, _create_row, _parse_datatype_json_string
@@ -190,7 +191,11 @@ def toImage(self, array, origin=""):
# Running `bytearray(numpy.array([1]))` fails in specific Python versions
# with a specific Numpy version, for example in Python 3.6.0 and NumPy 1.13.3.
# Here, it avoids it by converting it to bytes.
- data = bytearray(array.astype(dtype=np.uint8).ravel().tobytes())
+ if LooseVersion(np.__version__) >= LooseVersion('1.9'):
+ data = bytearray(array.astype(dtype=np.uint8).ravel().tobytes())
+ else:
+ # Numpy prior to 1.9 don't have `tobytes` method.
+ data = bytearray(array.astype(dtype=np.uint8).ravel())
# Creating new Row with _create_row(), because Row(name = value, ... )
# orders fields by name, which conflicts with expected schema order
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org