Skip to content

Commit

Permalink
[SPARK-38297][PYTHON] Explicitly cast the return value at DataFrame.t…
Browse files Browse the repository at this point in the history
…o_numpy in POS

MyPy build currently fails as below:

```
starting mypy annotations test...
annotations failed mypy checks:
python/pyspark/pandas/generic.py:585: error: Incompatible return value type (got "Union[ndarray[Any, Any], ExtensionArray]", expected "ndarray[Any, Any]")  [return-value]
Found 1 error in 1 file (checked 324 source files)
1
```

https://github.com/apache/spark/runs/5298261168?check_suite_focus=true

I tried to reproduce in my local by matching NumPy and MyPy versions but failed. So I decided to work around the problem first by explicitly casting to make MyPy happy.

To make the build pass.

No, dev-only.

CI in this PR should verify if it's fixed.

Closes #35617 from HyukjinKwon/SPARK-38297.

Authored-by: Hyukjin Kwon <gurwls223@apache.org>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
(cherry picked from commit b46b74c)
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
  • Loading branch information
HyukjinKwon committed Feb 24, 2022
1 parent 2b3ece5 commit 3ee9f78
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion python/pyspark/pandas/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def to_numpy(self) -> np.ndarray:
>>> ps.Series(['a', 'b', 'a']).to_numpy()
array(['a', 'b', 'a'], dtype=object)
"""
return self.to_pandas().values
return cast(np.ndarray, self.to_pandas().values)

@property
def values(self) -> np.ndarray:
Expand Down

0 comments on commit 3ee9f78

Please sign in to comment.