@@ -2355,6 +2355,214 @@ def test_types_to_numpy() -> None:
23552355 pd .Period ,
23562356 )
23572357
2358+ # np.dtypes signed int instances
2359+ check (
2360+ assert_type (
2361+ s_td_small .to_numpy (dtype = np .dtypes .Int8DType ()), np_1darray [np .int8 ]
2362+ ),
2363+ np_1darray ,
2364+ np .int8 ,
2365+ )
2366+ check (
2367+ assert_type (
2368+ s_td_small .to_numpy (dtype = np .dtypes .Int16DType ()), np_1darray [np .int16 ]
2369+ ),
2370+ np_1darray ,
2371+ np .int16 ,
2372+ )
2373+ check (
2374+ assert_type (
2375+ s_td_small .to_numpy (dtype = np .dtypes .Int32DType ()), np_1darray [np .int32 ]
2376+ ),
2377+ np_1darray ,
2378+ np .int32 ,
2379+ )
2380+ check (
2381+ assert_type (
2382+ s_td_small .to_numpy (dtype = np .dtypes .Int64DType ()), np_1darray [np .int64 ]
2383+ ),
2384+ np_1darray ,
2385+ np .int64 ,
2386+ )
2387+ check (
2388+ assert_type (
2389+ s_td_small .to_numpy (dtype = np .dtypes .IntDType ()), np_1darray [np .intc ]
2390+ ),
2391+ np_1darray ,
2392+ np .intc ,
2393+ )
2394+ check (
2395+ assert_type (
2396+ s_td_small .to_numpy (dtype = np .dtypes .LongDType ()), np_1darray [np .long ]
2397+ ),
2398+ np_1darray ,
2399+ np .long ,
2400+ )
2401+ check (
2402+ assert_type (
2403+ s_td_small .to_numpy (dtype = np .dtypes .LongLongDType ()),
2404+ np_1darray [np .longlong ],
2405+ ),
2406+ np_1darray ,
2407+ np .longlong ,
2408+ )
2409+
2410+ # np.dtypes unsigned int instances
2411+ check (
2412+ assert_type (
2413+ s_td_small .to_numpy (dtype = np .dtypes .UInt8DType ()), np_1darray [np .uint8 ]
2414+ ),
2415+ np_1darray ,
2416+ np .uint8 ,
2417+ )
2418+ check (
2419+ assert_type (
2420+ s_td_small .to_numpy (dtype = np .dtypes .UInt16DType ()), np_1darray [np .uint16 ]
2421+ ),
2422+ np_1darray ,
2423+ np .uint16 ,
2424+ )
2425+ check (
2426+ assert_type (
2427+ s_td_small .to_numpy (dtype = np .dtypes .UInt32DType ()), np_1darray [np .uint32 ]
2428+ ),
2429+ np_1darray ,
2430+ np .uint32 ,
2431+ )
2432+ check (
2433+ assert_type (
2434+ s_td_small .to_numpy (dtype = np .dtypes .UInt64DType ()), np_1darray [np .uint64 ]
2435+ ),
2436+ np_1darray ,
2437+ np .uint64 ,
2438+ )
2439+ check (
2440+ assert_type (
2441+ s_td_small .to_numpy (dtype = np .dtypes .UIntDType ()), np_1darray [np .uintc ]
2442+ ),
2443+ np_1darray ,
2444+ np .uintc ,
2445+ )
2446+ check (
2447+ assert_type (
2448+ s_td_small .to_numpy (dtype = np .dtypes .ULongDType ()), np_1darray [np .ulong ]
2449+ ),
2450+ np_1darray ,
2451+ np .ulong ,
2452+ )
2453+ check (
2454+ assert_type (
2455+ s_td_small .to_numpy (dtype = np .dtypes .ULongLongDType ()),
2456+ np_1darray [np .ulonglong ],
2457+ ),
2458+ np_1darray ,
2459+ np .ulonglong ,
2460+ )
2461+
2462+ # np.dtypes float instances
2463+ check (
2464+ assert_type (
2465+ s_td_small .to_numpy (dtype = np .dtypes .Float16DType ()), np_1darray [np .float16 ]
2466+ ),
2467+ np_1darray ,
2468+ np .float16 ,
2469+ )
2470+ check (
2471+ assert_type (
2472+ s_td_small .to_numpy (dtype = np .dtypes .Float32DType ()), np_1darray [np .float32 ]
2473+ ),
2474+ np_1darray ,
2475+ np .float32 ,
2476+ )
2477+ check (
2478+ assert_type (
2479+ s_timedelta .to_numpy (dtype = np .dtypes .Float64DType ()), np_1darray [np .float64 ]
2480+ ),
2481+ np_1darray ,
2482+ np .float64 ,
2483+ )
2484+ check (
2485+ assert_type (
2486+ s_td_small .to_numpy (dtype = np .dtypes .LongDoubleDType ()),
2487+ np_1darray [np .longdouble ],
2488+ ),
2489+ np_1darray ,
2490+ np .longdouble ,
2491+ )
2492+
2493+ # np.dtypes complex instances
2494+ check (
2495+ assert_type (
2496+ s_td_small .to_numpy (dtype = np .dtypes .Complex64DType ()),
2497+ np_1darray [np .complex64 ],
2498+ ),
2499+ np_1darray ,
2500+ np .complex64 ,
2501+ )
2502+ check (
2503+ assert_type (
2504+ s_td_small .to_numpy (dtype = np .dtypes .Complex128DType ()),
2505+ np_1darray [np .complex128 ],
2506+ ),
2507+ np_1darray ,
2508+ np .complex128 ,
2509+ )
2510+ check (
2511+ assert_type (
2512+ s_td_small .to_numpy (dtype = np .dtypes .CLongDoubleDType ()),
2513+ np_1darray [np .clongdouble ],
2514+ ),
2515+ np_1darray ,
2516+ np .clongdouble ,
2517+ )
2518+
2519+ # np.dtypes.BytesDType(size) — fixed-width bytes
2520+ check (
2521+ assert_type (
2522+ s_td_small .to_numpy (dtype = np .dtypes .BytesDType (4 )), np_1darray [np .bytes_ ]
2523+ ),
2524+ np_1darray ,
2525+ np .bytes_ ,
2526+ )
2527+ # np.dtypes.StrDType(size) — fixed-width unicode
2528+ check (
2529+ assert_type (
2530+ s_td_small .to_numpy (dtype = np .dtypes .StrDType (4 )), np_1darray [np .str_ ]
2531+ ),
2532+ np_1darray ,
2533+ np .str_ ,
2534+ )
2535+ # DateTime64DType — parametric, use np.dtype(...)
2536+ check (
2537+ assert_type (s_date .to_numpy (dtype = np .dtype ("datetime64[ns]" )), np_1darray_dt ),
2538+ np_1darray ,
2539+ np .datetime64 ,
2540+ )
2541+ # TimeDelta64DType — parametric, use np.dtype(...)
2542+ check (
2543+ assert_type (
2544+ s_td_small .to_numpy (dtype = np .dtype ("timedelta64[ns]" )), np_1darray_td
2545+ ),
2546+ np_1darray ,
2547+ np .timedelta64 ,
2548+ )
2549+ check (
2550+ assert_type (
2551+ s_td_small .to_numpy (dtype = np .dtype ("timedelta64[ns]" )), np_1darray_td
2552+ ),
2553+ np_1darray ,
2554+ np .timedelta64 ,
2555+ )
2556+ # VoidDType — parametric, use np.dtype(...)
2557+ check (
2558+ assert_type (
2559+ s_td_small .to_numpy (dtype = np .dtype ([("x" , np .float64 )])),
2560+ np_1darray [np .void ],
2561+ ),
2562+ np_1darray ,
2563+ np .void ,
2564+ )
2565+
23582566
23592567def test_where () -> None :
23602568 sr = pd .Series ([1 , 2 , 3 ], dtype = int )
0 commit comments