"""Tests for :mod:`_core.fromnumeric`."""

import datetime as dt
from typing import Any, assert_type

import numpy as np
import numpy.typing as npt

class NDArraySubclass(np.ndarray[tuple[Any, ...], np.dtype[np.complex128]]): ...

AR_b: npt.NDArray[np.bool]
AR_f4: npt.NDArray[np.float32]
AR_f4_1d: np.ndarray[tuple[int], np.dtype[np.float32]]
AR_f4_2d: np.ndarray[tuple[int, int], np.dtype[np.float32]]
AR_f4_3d: np.ndarray[tuple[int, int, int], np.dtype[np.float32]]
AR_c8: npt.NDArray[np.complex64]
AR_c16: npt.NDArray[np.complex128]
AR_i1: npt.NDArray[np.int8]
AR_u8: npt.NDArray[np.uint64]
AR_i8: npt.NDArray[np.int64]
AR_O: npt.NDArray[np.object_]
AR_subclass: NDArraySubclass
AR_m_ns: npt.NDArray[np.timedelta64[int]]
AR_m_s: npt.NDArray[np.timedelta64[dt.timedelta]]
AR_m_nat: npt.NDArray[np.timedelta64[None]]
AR_M_ns: npt.NDArray[np.datetime64[int]]
AR_0d: np.ndarray[tuple[()]]
AR_1d: np.ndarray[tuple[int]]
AR_nd: np.ndarray

b: np.bool
f4: np.float32
i8: np.int64
f: float

_py_list_1d: list[int]
_py_list_2d: list[list[int]]
_py_list_3d: list[list[list[int]]]

_dtype_list: list[np.dtype]
_any_list: list[Any]

# integer‑dtype subclass for argmin/argmax
class NDArrayIntSubclass(np.ndarray[tuple[Any, ...], np.dtype[np.intp]]): ...
AR_sub_i: NDArrayIntSubclass

assert_type(np.take(b, 0), np.bool)
assert_type(np.take(f4, 0), np.float32)
assert_type(np.take(f, 0), Any)
assert_type(np.take(AR_b, 0), np.bool)
assert_type(np.take(AR_f4, 0), np.float32)
assert_type(np.take(AR_b, [0]), npt.NDArray[np.bool])
assert_type(np.take(AR_f4, [0]), npt.NDArray[np.float32])
assert_type(np.take([1], [0]), npt.NDArray[Any])
assert_type(np.take(AR_f4, [0], out=AR_subclass), NDArraySubclass)

assert_type(np.reshape(b, 1), np.ndarray[tuple[int], np.dtype[np.bool]])
assert_type(np.reshape(f4, 1), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.reshape(f, 1), np.ndarray[tuple[int], np.dtype])
assert_type(np.reshape(AR_b, 1), np.ndarray[tuple[int], np.dtype[np.bool]])
assert_type(np.reshape(AR_f4, 1), np.ndarray[tuple[int], np.dtype[np.float32]])

assert_type(np.choose(1, [True, True]), Any)
assert_type(np.choose([1], [True, True]), npt.NDArray[Any])
assert_type(np.choose([1], AR_b), npt.NDArray[np.bool])
assert_type(np.choose([1], AR_b, out=AR_f4), npt.NDArray[np.float32])

assert_type(np.repeat(b, 1), np.ndarray[tuple[int], np.dtype[np.bool]])
assert_type(np.repeat(b, 1, axis=0), npt.NDArray[np.bool])
assert_type(np.repeat(f4, 1), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.repeat(f, 1), np.ndarray[tuple[int], np.dtype[Any]])
assert_type(np.repeat(AR_b, 1), np.ndarray[tuple[int], np.dtype[np.bool]])
assert_type(np.repeat(AR_f4, 1), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.repeat(AR_f4, 1, axis=0), npt.NDArray[np.float32])

# TODO: array_bdd tests for np.put()

assert_type(np.swapaxes([[0, 1]], 0, 0), npt.NDArray[Any])
assert_type(np.swapaxes(AR_b, 0, 0), npt.NDArray[np.bool])
assert_type(np.swapaxes(AR_f4, 0, 0), npt.NDArray[np.float32])

assert_type(np.transpose(b), npt.NDArray[np.bool])
assert_type(np.transpose(f4), npt.NDArray[np.float32])
assert_type(np.transpose(f), npt.NDArray[Any])
assert_type(np.transpose(AR_b), npt.NDArray[np.bool])
assert_type(np.transpose(AR_f4), npt.NDArray[np.float32])
assert_type(np.transpose(AR_f4_1d), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.transpose(AR_f4_2d), np.ndarray[tuple[int, int], np.dtype[np.float32]])

assert_type(np.partition(AR_b, 0), npt.NDArray[np.bool])
assert_type(np.partition(AR_b, 0, axis=None), np.ndarray[tuple[int], np.dtype[np.bool]])
assert_type(np.partition(AR_f4, 0), npt.NDArray[np.float32])
assert_type(np.partition(AR_f4, 0, axis=None), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.partition(AR_f4_1d, 0), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.partition(AR_f4_2d, 0), np.ndarray[tuple[int, int], np.dtype[np.float32]])
assert_type(np.partition(AR_f4_3d, 0), np.ndarray[tuple[int, int, int], np.dtype[np.float32]])

assert_type(np.argpartition(b, 0), npt.NDArray[np.intp])
assert_type(np.argpartition(f4, 0), npt.NDArray[np.intp])
assert_type(np.argpartition(f, 0), npt.NDArray[np.intp])
assert_type(np.argpartition(AR_b, 0), npt.NDArray[np.intp])
assert_type(np.argpartition(AR_f4, 0), npt.NDArray[np.intp])
assert_type(np.argpartition(b, 0, axis=None), np.ndarray[tuple[int], np.dtype[np.intp]])
assert_type(np.argpartition(f4, 0, axis=None), np.ndarray[tuple[int], np.dtype[np.intp]])
assert_type(np.argpartition(f, 0, axis=None), np.ndarray[tuple[int], np.dtype[np.intp]])
assert_type(np.argpartition(AR_b, 0, axis=None), np.ndarray[tuple[int], np.dtype[np.intp]])
assert_type(np.argpartition(AR_f4, 0, axis=None), np.ndarray[tuple[int], np.dtype[np.intp]])

assert_type(np.sort([2, 1]), npt.NDArray[Any])
assert_type(np.sort(AR_b), npt.NDArray[np.bool])
assert_type(np.sort(AR_f4), npt.NDArray[np.float32])
assert_type(np.sort(AR_f4_1d), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.sort(AR_f4_2d), np.ndarray[tuple[int, int], np.dtype[np.float32]])
assert_type(np.sort([2, 1], axis=None), np.ndarray[tuple[int]])
assert_type(np.sort(AR_b, axis=None), np.ndarray[tuple[int], np.dtype[np.bool]])
assert_type(np.sort(AR_f4, axis=None), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.sort(AR_f4_1d, axis=None), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.sort(AR_f4_2d, axis=None), np.ndarray[tuple[int], np.dtype[np.float32]])

assert_type(np.argsort([2, 1]), npt.NDArray[np.intp])
assert_type(np.argsort(AR_b), npt.NDArray[np.intp])
assert_type(np.argsort(AR_f4), npt.NDArray[np.intp])
assert_type(np.argsort(AR_f4_1d), np.ndarray[tuple[int], np.dtype[np.intp]])
assert_type(np.argsort(AR_f4_2d), np.ndarray[tuple[int, int], np.dtype[np.intp]])
assert_type(np.argsort([2, 1], axis=None), np.ndarray[tuple[int], np.dtype[np.intp]])
assert_type(np.argsort(AR_b, axis=None), np.ndarray[tuple[int], np.dtype[np.intp]])
assert_type(np.argsort(AR_f4, axis=None), np.ndarray[tuple[int], np.dtype[np.intp]])
assert_type(np.argsort(AR_f4_1d, axis=None), np.ndarray[tuple[int], np.dtype[np.intp]])
assert_type(np.argsort(AR_f4_2d, axis=None), np.ndarray[tuple[int], np.dtype[np.intp]])

# same as below
assert_type(np.argmax(AR_f4), np.intp)
assert_type(np.argmax(AR_f4, axis=0), npt.NDArray[np.intp])
assert_type(np.argmax(AR_f4, keepdims=True), npt.NDArray[np.intp])
assert_type(np.argmax(AR_f4_1d, keepdims=True), np.ndarray[tuple[int], np.dtype[np.intp]])
assert_type(np.argmax(AR_f4_2d, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.intp]])
assert_type(np.argmax(AR_f4_3d, keepdims=True), np.ndarray[tuple[int, int, int], np.dtype[np.intp]])
assert_type(np.argmax(AR_f4, out=AR_sub_i), NDArrayIntSubclass)

# same as above
assert_type(np.argmin(AR_f4), np.intp)
assert_type(np.argmin(AR_f4, axis=0), npt.NDArray[np.intp])
assert_type(np.argmin(AR_f4, keepdims=True), npt.NDArray[np.intp])
assert_type(np.argmin(AR_f4_1d, keepdims=True), np.ndarray[tuple[int], np.dtype[np.intp]])
assert_type(np.argmin(AR_f4_2d, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.intp]])
assert_type(np.argmin(AR_f4_3d, keepdims=True), np.ndarray[tuple[int, int, int], np.dtype[np.intp]])
assert_type(np.argmin(AR_f4, out=AR_sub_i), NDArrayIntSubclass)

assert_type(np.searchsorted(AR_b[0], 0), np.intp)
assert_type(np.searchsorted(AR_f4[0], 0), np.intp)
assert_type(np.searchsorted(AR_b[0], [0]), npt.NDArray[np.intp])
assert_type(np.searchsorted(AR_f4[0], [0]), npt.NDArray[np.intp])

assert_type(np.resize(b, (5, 5)), np.ndarray[tuple[int, int], np.dtype[np.bool]])
assert_type(np.resize(f4, (5, 5)), np.ndarray[tuple[int, int], np.dtype[np.float32]])
assert_type(np.resize(f, (5, 5)), np.ndarray[tuple[int, int], np.dtype])
assert_type(np.resize(AR_b, (5, 5)), np.ndarray[tuple[int, int], np.dtype[np.bool]])
assert_type(np.resize(AR_f4, (5, 5)), np.ndarray[tuple[int, int], np.dtype[np.float32]])

assert_type(np.squeeze(b), np.bool)
assert_type(np.squeeze(f4), np.float32)
assert_type(np.squeeze(f), npt.NDArray[Any])
assert_type(np.squeeze(AR_b), npt.NDArray[np.bool])
assert_type(np.squeeze(AR_f4), npt.NDArray[np.float32])

assert_type(np.diagonal(AR_b), npt.NDArray[np.bool])
assert_type(np.diagonal(AR_f4), npt.NDArray[np.float32])
assert_type(np.diagonal(AR_f4_2d), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.diagonal(AR_f4_3d), np.ndarray[tuple[int, int], np.dtype[np.float32]])

assert_type(np.trace(AR_b), Any)
assert_type(np.trace(AR_f4), Any)
assert_type(np.trace(AR_f4, out=AR_subclass), NDArraySubclass)
assert_type(np.trace(AR_f4, out=AR_subclass, dtype=None), NDArraySubclass)

assert_type(np.ravel(b), np.ndarray[tuple[int], np.dtype[np.bool]])
assert_type(np.ravel(f4), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.ravel(f), np.ndarray[tuple[int], np.dtype[np.float64 | Any]])
assert_type(np.ravel(AR_b), np.ndarray[tuple[int], np.dtype[np.bool]])
assert_type(np.ravel(AR_f4), np.ndarray[tuple[int], np.dtype[np.float32]])

type _Int1D = np.ndarray[tuple[int], np.dtype[np.intp]]

assert_type(np.nonzero(AR_f4), tuple[_Int1D, ...])
assert_type(np.nonzero(AR_f4_1d), tuple[_Int1D])
assert_type(np.nonzero(AR_f4_2d), tuple[_Int1D, _Int1D])
assert_type(np.nonzero(AR_f4_3d), tuple[_Int1D, _Int1D, _Int1D])

assert_type(np.shape(b), tuple[()])
assert_type(np.shape(f), tuple[()])
assert_type(np.shape([1]), tuple[int])
assert_type(np.shape([[2]]), tuple[int, int])
assert_type(np.shape([[[3]]]), tuple[int, int, int])
assert_type(np.shape(_py_list_1d), tuple[int])
assert_type(np.shape(_py_list_2d), tuple[int, int])
assert_type(np.shape(_py_list_3d), tuple[int, int, int])
assert_type(np.shape(AR_b), tuple[Any, ...])
assert_type(np.shape(AR_nd), tuple[Any, ...])
# these fail on mypy, but it works as expected with pyright/pylance
# assert_type(np.shape(AR_0d), tuple[()])
# assert_type(np.shape(AR_1d), tuple[int])
# assert_type(np.shape(AR_2d), tuple[int, int])

assert_type(np.compress([True], b), npt.NDArray[np.bool])
assert_type(np.compress([True], f4), npt.NDArray[np.float32])
assert_type(np.compress([True], f), npt.NDArray[Any])
assert_type(np.compress([True], AR_b), npt.NDArray[np.bool])
assert_type(np.compress([True], AR_f4), npt.NDArray[np.float32])

assert_type(np.clip(b, 0, 1.0), np.bool)
assert_type(np.clip(f4, -1, 1), np.float32)
assert_type(np.clip(f, 0, 1), Any)
assert_type(np.clip(AR_b, 0, 1), npt.NDArray[np.bool])
assert_type(np.clip(AR_f4, 0, 1), npt.NDArray[np.float32])
assert_type(np.clip([0], 0, 1), npt.NDArray[Any])
assert_type(np.clip(AR_b, 0, 1, out=AR_subclass), NDArraySubclass)
assert_type(np.clip(AR_f4_1d, 0, 1), np.ndarray[tuple[int], np.dtype[np.float32]])

assert_type(np.all(b), np.bool)
assert_type(np.all(f4), np.bool)
assert_type(np.all(f), np.bool)
assert_type(np.all(AR_b), np.bool)
assert_type(np.all(AR_f4), np.bool)
assert_type(np.all(AR_b, axis=0), npt.NDArray[np.bool])
assert_type(np.all(AR_f4, axis=0), npt.NDArray[np.bool])
assert_type(np.all(AR_b, keepdims=True), npt.NDArray[np.bool])
assert_type(np.all(AR_f4, keepdims=True), npt.NDArray[np.bool])
assert_type(np.all(AR_f4_1d, keepdims=True), np.ndarray[tuple[int], np.dtype[np.bool]])
assert_type(np.all(AR_f4_2d, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.bool]])
assert_type(np.all(AR_f4_3d, keepdims=True), np.ndarray[tuple[int, int, int], np.dtype[np.bool]])
assert_type(np.all(AR_f4, out=AR_subclass), NDArraySubclass)

assert_type(np.any(b), np.bool)
assert_type(np.any(f4), np.bool)
assert_type(np.any(f), np.bool)
assert_type(np.any(AR_b), np.bool)
assert_type(np.any(AR_f4), np.bool)
assert_type(np.any(AR_b, axis=0), npt.NDArray[np.bool])
assert_type(np.any(AR_f4, axis=0), npt.NDArray[np.bool])
assert_type(np.any(AR_b, keepdims=True), npt.NDArray[np.bool])
assert_type(np.any(AR_f4, keepdims=True), npt.NDArray[np.bool])
assert_type(np.any(AR_f4_1d, keepdims=True), np.ndarray[tuple[int], np.dtype[np.bool]])
assert_type(np.any(AR_f4_2d, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.bool]])
assert_type(np.any(AR_f4_3d, keepdims=True), np.ndarray[tuple[int, int, int], np.dtype[np.bool]])
assert_type(np.any(AR_f4, out=AR_subclass), NDArraySubclass)

assert_type(np.cumsum(b), np.ndarray[tuple[int], np.dtype[np.int_]])
assert_type(np.cumsum(f4), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.cumsum(f), np.ndarray[tuple[int]])
assert_type(np.cumsum(AR_b), np.ndarray[tuple[int], np.dtype[np.int_]])
assert_type(np.cumsum(AR_b, axis=0), npt.NDArray[np.int_])
assert_type(np.cumsum(AR_i1), np.ndarray[tuple[int], np.dtype[np.int_]])
assert_type(np.cumsum(AR_i1, axis=0), npt.NDArray[np.int_])
assert_type(np.cumsum(AR_f4), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.cumsum(AR_f4, axis=0), npt.NDArray[np.float32])
assert_type(np.cumsum(f, dtype=float), np.ndarray[tuple[int]])
assert_type(np.cumsum(f, dtype=np.float64), np.ndarray[tuple[int], np.dtype[np.float64]])
assert_type(np.cumsum(AR_f4, out=AR_subclass), NDArraySubclass)

assert_type(np.cumulative_sum(b), np.ndarray[tuple[int], np.dtype[np.int_]])
assert_type(np.cumulative_sum(f4), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.cumulative_sum(f), np.ndarray[tuple[int]])
assert_type(np.cumulative_sum(AR_b), np.ndarray[tuple[int], np.dtype[np.int_]])
assert_type(np.cumulative_sum(AR_b, axis=0), npt.NDArray[np.int_])
assert_type(np.cumulative_sum(AR_i1), np.ndarray[tuple[int], np.dtype[np.int_]])
assert_type(np.cumulative_sum(AR_i1, axis=0), npt.NDArray[np.int_])
assert_type(np.cumulative_sum(AR_f4), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.cumulative_sum(AR_f4, axis=0), npt.NDArray[np.float32])
assert_type(np.cumulative_sum(f, dtype=float), np.ndarray[tuple[int]])
assert_type(np.cumulative_sum(f, dtype=np.float64), np.ndarray[tuple[int], np.dtype[np.float64]])
assert_type(np.cumulative_sum(AR_f4, out=AR_subclass), NDArraySubclass)

assert_type(np.ptp(AR_i8), np.int64)
assert_type(np.ptp(AR_i8, axis=0), npt.NDArray[np.int64])
assert_type(np.ptp(AR_i8, keepdims=True), npt.NDArray[np.int64])
assert_type(np.ptp(AR_i8, axis=0, keepdims=True), npt.NDArray[np.int64])
assert_type(np.ptp(AR_f4), np.float32)
assert_type(np.ptp(AR_c16), np.complex128)
assert_type(np.ptp(AR_O), Any)
assert_type(np.ptp(AR_O, axis=0), npt.NDArray[np.object_])
assert_type(np.ptp(AR_O, keepdims=True), npt.NDArray[np.object_])
assert_type(np.ptp(AR_O, axis=0, keepdims=True), npt.NDArray[np.object_])
assert_type(np.ptp(AR_m_ns), np.timedelta64[int])
assert_type(np.ptp(AR_m_s), np.timedelta64[dt.timedelta])
assert_type(np.ptp(AR_m_nat), np.timedelta64[None])
assert_type(np.ptp(AR_M_ns), np.timedelta64)
assert_type(np.ptp(AR_f4, axis=0), npt.NDArray[np.float32])
assert_type(np.ptp(AR_f4, keepdims=True), npt.NDArray[np.float32])
assert_type(np.ptp(AR_f4_1d, keepdims=True), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.ptp(AR_f4_2d, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.float32]])
assert_type(np.ptp(AR_f4, out=AR_subclass), NDArraySubclass)
assert_type(np.ptp(AR_nd), Any)

# same as below
assert_type(np.amax(AR_i8), np.int64)
assert_type(np.amax(AR_i8, axis=0), npt.NDArray[np.int64])
assert_type(np.amax(AR_i8, keepdims=True), npt.NDArray[np.int64])
assert_type(np.amax(AR_i8, axis=0, keepdims=True), npt.NDArray[np.int64])
assert_type(np.amax(AR_b), np.bool)
assert_type(np.amax(AR_f4), np.float32)
assert_type(np.amax(AR_c16), np.complex128)
assert_type(np.amax(AR_O), Any)
assert_type(np.amax(AR_O, axis=0), npt.NDArray[np.object_])
assert_type(np.amax(AR_O, keepdims=True), npt.NDArray[np.object_])
assert_type(np.amax(AR_O, axis=0, keepdims=True), npt.NDArray[np.object_])
assert_type(np.amax(AR_m_ns), np.timedelta64[int])
assert_type(np.amax(AR_m_s), np.timedelta64[dt.timedelta])
assert_type(np.amax(AR_m_nat), np.timedelta64[None])
assert_type(np.amax(AR_M_ns), np.datetime64[int])
assert_type(np.amax(AR_f4, axis=0), npt.NDArray[np.float32])
assert_type(np.amax(AR_f4, keepdims=True), npt.NDArray[np.float32])
assert_type(np.amax(AR_f4_1d, keepdims=True), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.amax(AR_f4_2d, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.float32]])
assert_type(np.amax(AR_f4, out=AR_subclass), NDArraySubclass)
assert_type(np.amax(AR_nd), Any)
assert_type(np.amax(AR_nd, axis=1), np.ndarray)
assert_type(np.amax(AR_nd, keepdims=True), np.ndarray)
assert_type(np.amax(_dtype_list), Any)
assert_type(np.amax(_dtype_list, axis=1), npt.NDArray[Any])
assert_type(np.amax(_dtype_list, keepdims=True), npt.NDArray[Any])
assert_type(np.amax(_any_list), Any)

# same as above
assert_type(np.amin(AR_i8), np.int64)
assert_type(np.amin(AR_i8, axis=0), npt.NDArray[np.int64])
assert_type(np.amin(AR_i8, keepdims=True), npt.NDArray[np.int64])
assert_type(np.amin(AR_i8, axis=0, keepdims=True), npt.NDArray[np.int64])
assert_type(np.amin(AR_b), np.bool)
assert_type(np.amin(AR_f4), np.float32)
assert_type(np.amin(AR_c16), np.complex128)
assert_type(np.amin(AR_O), Any)
assert_type(np.amin(AR_O, axis=0), npt.NDArray[np.object_])
assert_type(np.amin(AR_O, keepdims=True), npt.NDArray[np.object_])
assert_type(np.amin(AR_O, axis=0, keepdims=True), npt.NDArray[np.object_])
assert_type(np.amin(AR_m_ns), np.timedelta64[int])
assert_type(np.amin(AR_m_s), np.timedelta64[dt.timedelta])
assert_type(np.amin(AR_m_nat), np.timedelta64[None])
assert_type(np.amin(AR_M_ns), np.datetime64[int])
assert_type(np.amin(AR_f4, axis=0), npt.NDArray[np.float32])
assert_type(np.amin(AR_f4, keepdims=True), npt.NDArray[np.float32])
assert_type(np.amin(AR_f4_1d, keepdims=True), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.amin(AR_f4_2d, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.float32]])
assert_type(np.amin(AR_f4, out=AR_subclass), NDArraySubclass)
assert_type(np.amin(AR_nd), Any)
assert_type(np.amin(AR_nd, axis=1), np.ndarray)
assert_type(np.amin(AR_nd, keepdims=True), np.ndarray)
assert_type(np.amin(_dtype_list), Any)
assert_type(np.amin(_dtype_list, axis=1), npt.NDArray[Any])
assert_type(np.amin(_dtype_list, keepdims=True), npt.NDArray[Any])

assert_type(np.cumprod(b), np.ndarray[tuple[int], np.dtype[np.int_]])
assert_type(np.cumprod(f4), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.cumprod(f), np.ndarray[tuple[int]])
assert_type(np.cumprod(AR_b), np.ndarray[tuple[int], np.dtype[np.int_]])
assert_type(np.cumprod(AR_b, axis=0), npt.NDArray[np.int_])
assert_type(np.cumprod(AR_i1), np.ndarray[tuple[int], np.dtype[np.int_]])
assert_type(np.cumprod(AR_i1, axis=0), npt.NDArray[np.int_])
assert_type(np.cumprod(AR_f4), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.cumprod(AR_f4, axis=0), npt.NDArray[np.float32])
assert_type(np.cumprod(f, dtype=float), np.ndarray[tuple[int]])
assert_type(np.cumprod(f, dtype=np.float64), np.ndarray[tuple[int], np.dtype[np.float64]])
assert_type(np.cumprod(AR_f4, out=AR_subclass), NDArraySubclass)

assert_type(np.cumulative_prod(b), np.ndarray[tuple[int], np.dtype[np.int_]])
assert_type(np.cumulative_prod(f4), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.cumulative_prod(f), np.ndarray[tuple[int]])
assert_type(np.cumulative_prod(AR_b), np.ndarray[tuple[int], np.dtype[np.int_]])
assert_type(np.cumulative_prod(AR_b, axis=0), npt.NDArray[np.int_])
assert_type(np.cumulative_prod(AR_i1), np.ndarray[tuple[int], np.dtype[np.int_]])
assert_type(np.cumulative_prod(AR_i1, axis=0), npt.NDArray[np.int_])
assert_type(np.cumulative_prod(AR_f4), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.cumulative_prod(AR_f4, axis=0), npt.NDArray[np.float32])
assert_type(np.cumulative_prod(f, dtype=float), np.ndarray[tuple[int]])
assert_type(np.cumulative_prod(f, dtype=np.float64), np.ndarray[tuple[int], np.dtype[np.float64]])
assert_type(np.cumulative_prod(AR_f4, out=AR_subclass), NDArraySubclass)

assert_type(np.ndim(b), int)
assert_type(np.ndim(f4), int)
assert_type(np.ndim(f), int)
assert_type(np.ndim(AR_b), int)
assert_type(np.ndim(AR_f4), int)

assert_type(np.size(b), int)
assert_type(np.size(f4), int)
assert_type(np.size(f), int)
assert_type(np.size(AR_b), int)
assert_type(np.size(AR_f4), int)

assert_type(np.around(b), np.float16)
assert_type(np.around(f), Any)
assert_type(np.around(i8), np.int64)
assert_type(np.around(f4), np.float32)
assert_type(np.around(AR_b), npt.NDArray[np.float16])
assert_type(np.around(AR_i8), npt.NDArray[np.int64])
assert_type(np.around(AR_f4), npt.NDArray[np.float32])
assert_type(np.around([1.5]), npt.NDArray[Any])
assert_type(np.around(AR_f4, out=AR_subclass), NDArraySubclass)
assert_type(np.around(AR_f4_1d), np.ndarray[tuple[int], np.dtype[np.float32]])

assert_type(np.prod(AR_nd), Any)
assert_type(np.prod(AR_b), np.int_)
assert_type(np.prod(AR_i1), np.int_)
assert_type(np.prod(AR_i1, axis=0), npt.NDArray[np.int_])
assert_type(np.prod(AR_i1, keepdims=True), npt.NDArray[np.int_])
assert_type(np.prod(AR_i1, axis=0, keepdims=True), npt.NDArray[np.int_])
assert_type(np.prod(AR_i8), np.int_)
assert_type(np.prod(AR_i8, axis=0), npt.NDArray[np.int_])
assert_type(np.prod(AR_i8, keepdims=True), npt.NDArray[np.int_])
assert_type(np.prod(AR_i8, axis=0, keepdims=True), npt.NDArray[np.int_])
assert_type(np.prod(AR_f4), np.float32)
assert_type(np.prod(AR_c16), np.complex128)
assert_type(np.prod(AR_O), Any)
assert_type(np.prod(AR_O, axis=0), npt.NDArray[np.object_])
assert_type(np.prod(AR_O, keepdims=True), npt.NDArray[np.object_])
assert_type(np.prod(AR_O, axis=0, keepdims=True), npt.NDArray[np.object_])
assert_type(np.prod(AR_f4, axis=0), npt.NDArray[np.float32])
assert_type(np.prod(AR_f4, keepdims=True), npt.NDArray[np.float32])
assert_type(np.prod(AR_f4_1d, keepdims=True), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.prod(AR_f4_2d, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.float32]])
assert_type(np.prod(AR_f4, dtype=float), Any)
assert_type(np.prod(AR_f4, dtype=float, axis=1), np.ndarray)
assert_type(np.prod(AR_f4, dtype=float, keepdims=True), np.ndarray)
assert_type(np.prod(AR_f4, dtype=float, axis=1, keepdims=True), np.ndarray)
assert_type(np.prod(AR_f4, dtype=np.float64), np.float64)
assert_type(np.prod(AR_f4, dtype=np.float64), np.float64)
assert_type(np.prod(AR_f4, dtype=np.float64, keepdims=False), np.float64)
assert_type(np.prod(AR_f4, dtype=np.float64, keepdims=True), npt.NDArray[np.float64])
assert_type(np.prod(AR_f4_1d, dtype=np.float64, keepdims=True), np.ndarray[tuple[int], np.dtype[np.float64]])
assert_type(np.prod(AR_f4_2d, dtype=np.float64, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.float64]])
assert_type(np.prod(AR_f4, out=AR_subclass), NDArraySubclass)

# same as above (but with `timedelta64`)
assert_type(np.sum(AR_nd), Any)
assert_type(np.sum(AR_b), np.int_)
assert_type(np.sum(AR_i1), np.int_)
assert_type(np.sum(AR_i1, axis=0), npt.NDArray[np.int_])
assert_type(np.sum(AR_i1, keepdims=True), npt.NDArray[np.int_])
assert_type(np.sum(AR_i1, axis=0, keepdims=True), npt.NDArray[np.int_])
assert_type(np.sum(AR_i8), np.int_)
assert_type(np.sum(AR_i8, axis=0), npt.NDArray[np.int_])
assert_type(np.sum(AR_i8, keepdims=True), npt.NDArray[np.int_])
assert_type(np.sum(AR_i8, axis=0, keepdims=True), npt.NDArray[np.int_])
assert_type(np.sum(AR_f4), np.float32)
assert_type(np.sum(AR_c16), np.complex128)
assert_type(np.sum(AR_O), Any)
assert_type(np.sum(AR_O, axis=0), npt.NDArray[np.object_])
assert_type(np.sum(AR_O, keepdims=True), npt.NDArray[np.object_])
assert_type(np.sum(AR_O, axis=0, keepdims=True), npt.NDArray[np.object_])
assert_type(np.sum(AR_m_ns), np.timedelta64[int])
assert_type(np.sum(AR_m_s), np.timedelta64[dt.timedelta])
assert_type(np.sum(AR_m_nat), np.timedelta64[None])
assert_type(np.sum(AR_f4, axis=0), npt.NDArray[np.float32])
assert_type(np.sum(AR_f4, keepdims=True), npt.NDArray[np.float32])
assert_type(np.sum(AR_f4_1d, keepdims=True), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.sum(AR_f4_2d, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.float32]])
assert_type(np.sum(AR_f4, dtype=float), Any)
assert_type(np.sum(AR_f4, dtype=float, axis=1), np.ndarray)
assert_type(np.sum(AR_f4, dtype=float, keepdims=True), np.ndarray)
assert_type(np.sum(AR_f4, dtype=float, axis=1, keepdims=True), np.ndarray)
assert_type(np.sum(AR_f4, dtype=np.float64), np.float64)
assert_type(np.sum(AR_f4, dtype=np.float64), np.float64)
assert_type(np.sum(AR_f4, dtype=np.float64, keepdims=False), np.float64)
assert_type(np.sum(AR_f4, dtype=np.float64, keepdims=True), npt.NDArray[np.float64])
assert_type(np.sum(AR_f4_1d, dtype=np.float64, keepdims=True), np.ndarray[tuple[int], np.dtype[np.float64]])
assert_type(np.sum(AR_f4_2d, dtype=np.float64, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.float64]])
assert_type(np.sum(AR_f4, out=AR_subclass), NDArraySubclass)

#
assert_type(np.mean(AR_b), np.float64)
assert_type(np.mean(AR_i8), np.float64)
assert_type(np.mean(AR_i8, axis=0), npt.NDArray[np.float64])
assert_type(np.mean(AR_i8, keepdims=True), npt.NDArray[np.float64])
assert_type(np.mean(AR_i8, axis=0, keepdims=True), npt.NDArray[np.float64])
assert_type(np.mean(AR_f4), np.float32)
assert_type(np.mean(AR_c16), np.complex128)
assert_type(np.mean(AR_O), np.float64)
assert_type(np.mean(AR_O, axis=0), npt.NDArray[np.object_])
assert_type(np.mean(AR_O, keepdims=True), npt.NDArray[np.object_])
assert_type(np.mean(AR_O, axis=0, keepdims=True), npt.NDArray[np.object_])
assert_type(np.mean(AR_m_ns), np.timedelta64[int])
assert_type(np.mean(AR_m_s), np.timedelta64[dt.timedelta])
assert_type(np.mean(AR_m_nat), np.timedelta64[None])
assert_type(np.mean(AR_f4, axis=0), npt.NDArray[np.float32])
assert_type(np.mean(AR_f4, keepdims=True), npt.NDArray[np.float32])
assert_type(np.mean(AR_f4_1d, keepdims=True), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.mean(AR_f4_2d, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.float32]])
assert_type(np.mean(AR_f4, dtype=float), Any)
assert_type(np.mean(AR_f4, dtype=float, axis=1), np.ndarray)
assert_type(np.mean(AR_f4, dtype=float, keepdims=True), np.ndarray)
assert_type(np.mean(AR_f4, dtype=float, axis=1, keepdims=True), np.ndarray)
assert_type(np.mean(AR_f4, dtype=np.float64), np.float64)
assert_type(np.mean(AR_f4, dtype=np.float64), np.float64)
assert_type(np.mean(AR_f4, dtype=np.float64, keepdims=False), np.float64)
assert_type(np.mean(AR_f4, dtype=np.float64, keepdims=True), npt.NDArray[np.float64])
assert_type(np.mean(AR_f4_1d, dtype=np.float64, keepdims=True), np.ndarray[tuple[int], np.dtype[np.float64]])
assert_type(np.mean(AR_f4_2d, dtype=np.float64, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.float64]])
assert_type(np.mean(AR_f4, out=AR_subclass), NDArraySubclass)

# same as above
assert_type(np.std(AR_b), np.float64)
assert_type(np.std(AR_i8), np.float64)
assert_type(np.std(AR_i8, axis=0), npt.NDArray[np.float64])
assert_type(np.std(AR_i8, keepdims=True), npt.NDArray[np.float64])
assert_type(np.std(AR_i8, axis=0, keepdims=True), npt.NDArray[np.float64])
assert_type(np.std(AR_f4), np.float32)
assert_type(np.std(AR_c8), Any)
assert_type(np.std(AR_c8, axis=0), npt.NDArray[Any])
assert_type(np.std(AR_c8, keepdims=True), npt.NDArray[Any])
assert_type(np.std(AR_c16), np.float64)
assert_type(np.std(AR_c16, axis=0), npt.NDArray[np.float64])
assert_type(np.std(AR_c16, keepdims=True), npt.NDArray[np.float64])
assert_type(np.std(AR_O), np.float64)
assert_type(np.std(AR_O, axis=0), npt.NDArray[np.object_])
assert_type(np.std(AR_O, keepdims=True), npt.NDArray[np.object_])
assert_type(np.std(AR_O, axis=0, keepdims=True), npt.NDArray[np.object_])
assert_type(np.std(AR_m_ns), np.timedelta64[int])
assert_type(np.std(AR_m_s), np.timedelta64[dt.timedelta])
assert_type(np.std(AR_m_nat), np.timedelta64[None])
assert_type(np.std(AR_f4, axis=0), npt.NDArray[np.float32])
assert_type(np.std(AR_f4, keepdims=True), npt.NDArray[np.float32])
assert_type(np.std(AR_f4_1d, keepdims=True), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.std(AR_f4_2d, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.float32]])
assert_type(np.std(AR_f4, dtype=float), Any)
assert_type(np.std(AR_f4, dtype=float, axis=1), np.ndarray)
assert_type(np.std(AR_f4, dtype=float, keepdims=True), np.ndarray)
assert_type(np.std(AR_f4, dtype=float, axis=1, keepdims=True), np.ndarray)
assert_type(np.std(AR_f4, dtype=np.float64), np.float64)
assert_type(np.std(AR_f4, dtype=np.float64), np.float64)
assert_type(np.std(AR_f4, dtype=np.float64, keepdims=False), np.float64)
assert_type(np.std(AR_f4, dtype=np.float64, keepdims=True), npt.NDArray[np.float64])
assert_type(np.std(AR_f4_1d, dtype=np.float64, keepdims=True), np.ndarray[tuple[int], np.dtype[np.float64]])
assert_type(np.std(AR_f4_2d, dtype=np.float64, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.float64]])
assert_type(np.std(AR_f4, out=AR_subclass), NDArraySubclass)

# same as above
assert_type(np.var(AR_b), np.float64)
assert_type(np.var(AR_i8), np.float64)
assert_type(np.var(AR_i8, axis=0), npt.NDArray[np.float64])
assert_type(np.var(AR_i8, keepdims=True), npt.NDArray[np.float64])
assert_type(np.var(AR_i8, axis=0, keepdims=True), npt.NDArray[np.float64])
assert_type(np.var(AR_f4), np.float32)
assert_type(np.var(AR_c8), Any)
assert_type(np.var(AR_c8, axis=0), npt.NDArray[Any])
assert_type(np.var(AR_c8, keepdims=True), npt.NDArray[Any])
assert_type(np.var(AR_c16), np.float64)
assert_type(np.var(AR_c16, axis=0), npt.NDArray[np.float64])
assert_type(np.var(AR_c16, keepdims=True), npt.NDArray[np.float64])
assert_type(np.var(AR_O), np.float64)
assert_type(np.var(AR_O, axis=0), npt.NDArray[np.object_])
assert_type(np.var(AR_O, keepdims=True), npt.NDArray[np.object_])
assert_type(np.var(AR_O, axis=0, keepdims=True), npt.NDArray[np.object_])
assert_type(np.var(AR_m_ns), np.timedelta64[int])
assert_type(np.var(AR_m_s), np.timedelta64[dt.timedelta])
assert_type(np.var(AR_m_nat), np.timedelta64[None])
assert_type(np.var(AR_f4, axis=0), npt.NDArray[np.float32])
assert_type(np.var(AR_f4, keepdims=True), npt.NDArray[np.float32])
assert_type(np.var(AR_f4_1d, keepdims=True), np.ndarray[tuple[int], np.dtype[np.float32]])
assert_type(np.var(AR_f4_2d, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.float32]])
assert_type(np.var(AR_f4, dtype=float), Any)
assert_type(np.var(AR_f4, dtype=float, axis=1), np.ndarray)
assert_type(np.var(AR_f4, dtype=float, keepdims=True), np.ndarray)
assert_type(np.var(AR_f4, dtype=float, axis=1, keepdims=True), np.ndarray)
assert_type(np.var(AR_f4, dtype=np.float64), np.float64)
assert_type(np.var(AR_f4, dtype=np.float64), np.float64)
assert_type(np.var(AR_f4, dtype=np.float64, keepdims=False), np.float64)
assert_type(np.var(AR_f4, dtype=np.float64, keepdims=True), npt.NDArray[np.float64])
assert_type(np.var(AR_f4_1d, dtype=np.float64, keepdims=True), np.ndarray[tuple[int], np.dtype[np.float64]])
assert_type(np.var(AR_f4_2d, dtype=np.float64, keepdims=True), np.ndarray[tuple[int, int], np.dtype[np.float64]])
assert_type(np.var(AR_f4, out=AR_subclass), NDArraySubclass)

###

data: npt.NDArray[np.void]
polygons = data["vectors"].sum(axis=1)
