Skip to content

GH1182 Add numpy integer, floating, complex to Scalar #1192

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

Merged
merged 1 commit into from
Apr 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,9 @@ IndexIterScalar: TypeAlias = (
| Timestamp
| Timedelta
)
Scalar: TypeAlias = IndexIterScalar | complex
Scalar: TypeAlias = (
IndexIterScalar | complex | np.integer | np.floating | np.complexfloating
)
ScalarT = TypeVar("ScalarT", bound=Scalar)
# Refine the definitions below in 3.9 to use the specialized type.
np_ndarray_int64: TypeAlias = npt.NDArray[np.int64]
Expand Down
9 changes: 9 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,15 @@ def test_types_to_numpy() -> None:
# na_value param was added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
check(assert_type(df.to_numpy(na_value=0), np.ndarray), np.ndarray)

df = pd.DataFrame(data={"col1": [1, 1, 2]}, dtype=np.complex128)
check(assert_type(df.to_numpy(na_value=0), np.ndarray), np.ndarray)
check(assert_type(df.to_numpy(na_value=np.int32(4)), np.ndarray), np.ndarray)
check(assert_type(df.to_numpy(na_value=np.float16(3.68)), np.ndarray), np.ndarray)
check(
assert_type(df.to_numpy(na_value=np.complex128(3.8, -493.2)), np.ndarray),
np.ndarray,
)


def test_to_markdown() -> None:
df = pd.DataFrame(data={"col1": [1, 1, 2], "col2": [3, 4, 5]})
Expand Down
3 changes: 3 additions & 0 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,9 @@ def test_types_to_numpy() -> None:
check(assert_type(s.to_numpy(), np.ndarray), np.ndarray)
check(assert_type(s.to_numpy(dtype="str", copy=True), np.ndarray), np.ndarray)
check(assert_type(s.to_numpy(na_value=0), np.ndarray), np.ndarray)
check(assert_type(s.to_numpy(na_value=np.int32(4)), np.ndarray), np.ndarray)
check(assert_type(s.to_numpy(na_value=np.float16(4)), np.ndarray), np.ndarray)
check(assert_type(s.to_numpy(na_value=np.complex128(4, 7)), np.ndarray), np.ndarray)


def test_where() -> None:
Expand Down