summaryrefslogtreecommitdiff
path: root/numpy/tests/reveal/ndarray_conversion.py
blob: 411adcf63197927983f79d2356a2a8d8c66f7952 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import numpy as np

nd = np.array([[1, 2], [3, 4]])

# item
reveal_type(nd.item())  # E: Any
reveal_type(nd.item(1))  # E: Any
reveal_type(nd.item(0, 1))  # E: Any
reveal_type(nd.item((0, 1)))  # E: Any

# tolist
reveal_type(nd.tolist())  # E: builtins.list[Any]

# itemset does not return a value
# tostring is pretty simple
# tobytes is pretty simple
# tofile does not return a value
# dump does not return a value
# dumps is pretty simple

# astype
reveal_type(nd.astype("float"))  # E: numpy.ndarray
reveal_type(nd.astype(float))  # E: numpy.ndarray
reveal_type(nd.astype(float, "K"))  # E: numpy.ndarray
reveal_type(nd.astype(float, "K", "unsafe"))  # E: numpy.ndarray
reveal_type(nd.astype(float, "K", "unsafe", True))  # E: numpy.ndarray
reveal_type(nd.astype(float, "K", "unsafe", True, True))  # E: numpy.ndarray

# byteswap
reveal_type(nd.byteswap())  # E: numpy.ndarray
reveal_type(nd.byteswap(True))  # E: numpy.ndarray

# copy
reveal_type(nd.copy())  # E: numpy.ndarray
reveal_type(nd.copy("C"))  # E: numpy.ndarray

# view
class SubArray(np.ndarray):
    pass


reveal_type(nd.view())  # E: numpy.ndarray
reveal_type(nd.view(np.int64))  # E: numpy.ndarray
# replace `Any` with `numpy.matrix` when `matrix` will be added to stubs
reveal_type(nd.view(np.int64, np.matrix))  # E: Any
reveal_type(nd.view(np.int64, SubArray))  # E: SubArray

# getfield
reveal_type(nd.getfield("float"))  # E: numpy.ndarray
reveal_type(nd.getfield(float))  # E: numpy.ndarray
reveal_type(nd.getfield(float, 8))  # E: numpy.ndarray

# setflags does not return a value
# fill does not return a value