def test_array_of_different_depths(self): # When multiple arrays (or array-likes) are included in a # sequences and have different depth, we currently discover # as many dimensions as they share. (see also gh-17224) arr = np.zeros((3, 2)) mismatch_first_dim = np.zeros((1, 2)) mismatch_second_dim = np.zeros((3, 3)) dtype, shape = _discover_array_parameters([arr, mismatch_second_dim], dtype=np.dtype("O")) assert shape == (2, 3) dtype, shape = _discover_array_parameters([arr, mismatch_first_dim], dtype=np.dtype("O")) assert shape == (2, ) # The second case is currently supported because the arrays # can be stored as objects: res = np.asarray([arr, mismatch_first_dim], dtype=np.dtype("O")) assert res[0] is arr assert res[1] is mismatch_first_dim
def test_default_dtype_instance(self, dtype_char): if dtype_char in "SU": dtype = np.dtype(dtype_char + "1") elif dtype_char == "V": # Legacy behaviour was to use V8. The reason was float64 being the # default dtype and that having 8 bytes. dtype = np.dtype("V8") else: dtype = np.dtype(dtype_char) discovered_dtype, _ = _discover_array_parameters([], type(dtype)) assert discovered_dtype == dtype assert discovered_dtype.itemsize == dtype.itemsize