Skip to content

Conversation

@cmp0xff
Copy link
Contributor

@cmp0xff cmp0xff commented Nov 27, 2025

Comment on lines -442 to -446
np_1darray_bool: TypeAlias = np.ndarray[tuple[int], np.bool_]
np_1darray_str: TypeAlias = np.ndarray[tuple[int], np.str_]
np_1darray_bytes: TypeAlias = np.ndarray[tuple[int], np.bytes_]
np_1darray_complex: TypeAlias = np.ndarray[tuple[int], np.complexfloating]
np_1darray_object: TypeAlias = np.ndarray[tuple[int], np.object_]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These have been incorrect. Should have been np.ndarray[tuple[int], np.dtype[np.bool_]], etc.

Comment on lines 2031 to 2049
def test_types_to_numpy() -> None:
s = pd.Series(["a", "b", "c"], dtype=str)
check(assert_type(s.to_numpy(), np_1darray_str), np_1darray_str)
check(assert_type(s.to_numpy(), np_1darray_object), np_1darray_object)
check( # <U1, not str_
assert_type(s.to_numpy(dtype="str", copy=True), np_1darray), np_1darray
)
check(assert_type(s.to_numpy(na_value=0), np_1darray_object), np_1darray_object)
check(
assert_type(s.to_numpy(dtype="str", copy=True), np_1darray_str), np_1darray_str
assert_type(s.to_numpy(na_value=np.int32(4)), np_1darray_object),
np_1darray_object,
)
check(assert_type(s.to_numpy(na_value=0), np_1darray_str), np_1darray_str)
check(assert_type(s.to_numpy(na_value=np.int32(4)), np_1darray_str), np_1darray_str)
check(
assert_type(s.to_numpy(na_value=np.float16(4)), np_1darray_str), np_1darray_str
assert_type(s.to_numpy(na_value=np.float16(4)), np_1darray_object),
np_1darray_object,
)
check(
assert_type(s.to_numpy(na_value=np.complex128(4, 7)), np_1darray_str),
np_1darray_str,
assert_type(s.to_numpy(na_value=np.complex128(4, 7)), np_1darray_object),
np_1darray_object,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behavioural changes

"""Test Series.to_numpy for different types."""
s_str = pd.Series(["a", "b", "c"], dtype=str)
check(assert_type(s_str.to_numpy(), np_1darray_str), np_1darray_str)
check(assert_type(s_str.to_numpy(), np_1darray_object), np_1darray_object)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behavioural change

Comment on lines +1008 to +1013
# |S20, not bytes_
check(assert_type(o_s.to_numpy(dtype=np.bytes_), np_1darray), np_1darray)
# |S6, not bytes_
check(assert_type(i_s.to_numpy(dtype=np.bytes_), np_1darray), np_1darray)
# <U6, not str_
check(assert_type(i_s.to_numpy(dtype=np.str_), np_1darray), np_1darray)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behavioural changes

Comment on lines +1072 to +1073
# |S6, not bytes_
check(assert_type(i_i.to_numpy(dtype="bytes", copy=True), np_1darray), np_1darray)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behavioural change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove duplication of dtype/astype arguments between _typing.pyi and tests/__init__.py

1 participant