6060 check ,
6161 ensure_clean ,
6262 np_1darray ,
63+ np_1darray_anyint ,
64+ np_1darray_bool ,
65+ np_1darray_bytes ,
66+ np_1darray_complex ,
67+ np_1darray_datetime ,
68+ np_1darray_float ,
69+ np_1darray_object ,
70+ np_1darray_str ,
71+ np_1darray_timedelta ,
6372 pytest_warns_bounded ,
6473)
6574from tests .extension .decimal .array import DecimalDtype
@@ -2003,27 +2012,27 @@ def test_types_to_numpy() -> None:
20032012def test_to_numpy () -> None :
20042013 """Test Series.to_numpy for different types."""
20052014 s_str = pd .Series (["a" , "b" , "c" ], dtype = str )
2006- check (assert_type (s_str .to_numpy (), np_1darray [ np . str_ ] ), np_1darray , str )
2015+ check (assert_type (s_str .to_numpy (), np_1darray_str ), np_1darray , str )
20072016
20082017 s_bytes = pd .Series (["a" , "b" , "c" ]).astype (bytes )
2009- check (assert_type (s_bytes .to_numpy (), np_1darray [ np . bytes_ ] ), np_1darray , np .bytes_ )
2018+ check (assert_type (s_bytes .to_numpy (), np_1darray_bytes ), np_1darray , np .bytes_ )
20102019
20112020 s_bool = pd .Series ([True , False ])
2012- check (assert_type (s_bool .to_numpy (), np_1darray [ np . bool_ ] ), np_1darray , np .bool_ )
2021+ check (assert_type (s_bool .to_numpy (), np_1darray_bool ), np_1darray , np .bool_ )
20132022
20142023 s_int = pd .Series ([2 , 3 , 4 ])
2015- check (assert_type (s_int .to_numpy (), np_1darray [ np . integer ] ), np_1darray , np .integer )
2024+ check (assert_type (s_int .to_numpy (), np_1darray_anyint ), np_1darray , np .integer )
20162025
20172026 s_float = pd .Series ([2.0 , 3.54 , 4.84 ])
20182027 check (
2019- assert_type (s_float .to_numpy (), np_1darray [ np . floating ] ),
2028+ assert_type (s_float .to_numpy (), np_1darray_float ),
20202029 np_1darray ,
20212030 np .floating ,
20222031 )
20232032
20242033 s_complex = pd .Series ([2.0 + 2j , 3.54 + 4j , 4.84 ])
20252034 check (
2026- assert_type (s_complex .to_numpy (), np_1darray [ np . complexfloating ] ),
2035+ assert_type (s_complex .to_numpy (), np_1darray_complex ),
20272036 np_1darray ,
20282037 np .complexfloating ,
20292038 )
@@ -2037,24 +2046,24 @@ def test_to_numpy() -> None:
20372046 dtype = "datetime64[ns]" ,
20382047 )
20392048 s_period = pd .PeriodIndex (dates , freq = "M" ).to_series ()
2040- check (
2041- assert_type (s_period .to_numpy (), np_1darray [np .object_ ]), np_1darray , pd .Period
2042- )
2049+ check (assert_type (s_period .to_numpy (), np_1darray_object ), np_1darray , pd .Period )
20432050
2044- s8 = pd .Series (
2051+ s_interval = pd .Series (
20452052 [
20462053 pd .Interval (date , date + pd .DateOffset (days = 1 ), closed = "left" )
20472054 for date in dates
20482055 ]
20492056 )
2050- check (assert_type (s8 .to_numpy (), np_1darray [np .object_ ]), np_1darray , pd .Interval )
2057+ check (
2058+ assert_type (s_interval .to_numpy (), np_1darray_object ), np_1darray , pd .Interval
2059+ )
20512060
2052- s_interval = pd .Series ([Day (1 )])
2053- check (assert_type (s_interval .to_numpy (), np_1darray [ np . object_ ] ), np_1darray , Day )
2061+ s_day = pd .Series ([Day (1 )])
2062+ check (assert_type (s_day .to_numpy (), np_1darray_object ), np_1darray , Day )
20542063
20552064 s_date = pd .Series (pd .date_range (start = "2017-01-01" , end = "2017-02-01" ))
20562065 check (
2057- assert_type (s_date .to_numpy (), np_1darray [ np . datetime64 ] ),
2066+ assert_type (s_date .to_numpy (), np_1darray_datetime ),
20582067 np_1darray ,
20592068 np .datetime64 ,
20602069 )
@@ -2063,7 +2072,7 @@ def test_to_numpy() -> None:
20632072 [pd .Timestamp .now ().date (), pd .Timestamp .now ().date ()]
20642073 ).diff ()
20652074 check (
2066- assert_type (s_timedelta .to_numpy (), np_1darray [ np . timedelta64 ] ),
2075+ assert_type (s_timedelta .to_numpy (), np_1darray_timedelta ),
20672076 np_1darray ,
20682077 np .timedelta64 ,
20692078 )
0 commit comments