You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by gu...@apache.org on 2024/10/22 07:59:11 UTC
(spark) branch master updated: [SPARK-50051][PYTHON][FOLLOW-UP] Fix data type check for Numpy 1.x
This is an automated email from the ASF dual-hosted git repository.
gurwls223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 61db25138617 [SPARK-50051][PYTHON][FOLLOW-UP] Fix data type check for Numpy 1.x
61db25138617 is described below
commit 61db25138617c90e7bd8afcfae3723b3621c5fd8
Author: Ruifeng Zheng <ru...@apache.org>
AuthorDate: Tue Oct 22 16:59:00 2024 +0900
[SPARK-50051][PYTHON][FOLLOW-UP] Fix data type check for Numpy 1.x
### What changes were proposed in this pull request?
Fix type check for Numpy 1.x: `np.isdtype` is not available in Numpy 1.x
### Why are the changes needed?
```
In [13]: np.__version__
Out[13]: '1.26.4'
In [14]: a = np.str_("123")
In [15]: np.isdtype(a.dtype, np.str_)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[15], line 1
----> 1 np.isdtype(a.dtype, np.str_)
File ~/.dev/venv/py_312/lib/python3.12/site-packages/numpy/__init__.py:333, in __getattr__(attr)
330 "Removed in NumPy 1.25.0"
331 raise RuntimeError("Tester was removed in NumPy 1.25.")
--> 333 raise AttributeError("module {!r} has no attribute "
334 "{!r}".format(__name__, attr))
AttributeError: module 'numpy' has no attribute 'isdtype'
In [16]: a.dtype.type == np.dtype("str")
Out[16]: True
```
### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?
ci
### Was this patch authored or co-authored using generative AI tooling?
no
Closes #48592 from zhengruifeng/lit_empty_followup.
Authored-by: Ruifeng Zheng <ru...@apache.org>
Signed-off-by: Hyukjin Kwon <gu...@apache.org>
---
python/pyspark/sql/types.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/python/pyspark/sql/types.py b/python/pyspark/sql/types.py
index 0f77e95cced1..1773e0e9604a 100644
--- a/python/pyspark/sql/types.py
+++ b/python/pyspark/sql/types.py
@@ -3273,7 +3273,7 @@ class NumpyArrayConverter:
return gateway.jvm.double
elif nt == np.dtype("bool"):
return gateway.jvm.boolean
- elif np.isdtype(nt, np.str_):
+ elif nt.type == np.dtype("str"):
return gateway.jvm.String
return None
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org