Skip to content
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