summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/typing/tests/data/fail/arrayprint.py13
-rw-r--r--numpy/typing/tests/data/pass/arrayprint.py37
-rw-r--r--numpy/typing/tests/data/reveal/arrayprint.py19
3 files changed, 69 insertions, 0 deletions
diff --git a/numpy/typing/tests/data/fail/arrayprint.py b/numpy/typing/tests/data/fail/arrayprint.py
new file mode 100644
index 000000000..86297a0b2
--- /dev/null
+++ b/numpy/typing/tests/data/fail/arrayprint.py
@@ -0,0 +1,13 @@
+from typing import Callable, Any
+import numpy as np
+
+AR: np.ndarray
+func1: Callable[[Any], str]
+func2: Callable[[np.integer[Any]], str]
+
+np.array2string(AR, style=None) # E: Unexpected keyword argument
+np.array2string(AR, legacy="1.14") # E: incompatible type
+np.array2string(AR, sign="*") # E: incompatible type
+np.array2string(AR, floatmode="default") # E: incompatible type
+np.array2string(AR, formatter={"A": func1}) # E: incompatible type
+np.array2string(AR, formatter={"float": func2}) # E: Incompatible types
diff --git a/numpy/typing/tests/data/pass/arrayprint.py b/numpy/typing/tests/data/pass/arrayprint.py
new file mode 100644
index 000000000..6c704c755
--- /dev/null
+++ b/numpy/typing/tests/data/pass/arrayprint.py
@@ -0,0 +1,37 @@
+import numpy as np
+
+AR = np.arange(10)
+AR.setflags(write=False)
+
+with np.printoptions():
+ np.set_printoptions(
+ precision=1,
+ threshold=2,
+ edgeitems=3,
+ linewidth=4,
+ suppress=False,
+ nanstr="Bob",
+ infstr="Bill",
+ formatter={},
+ sign="+",
+ floatmode="unique",
+ )
+ np.get_printoptions()
+ str(AR)
+
+ np.array2string(
+ AR,
+ max_line_width=5,
+ precision=2,
+ suppress_small=True,
+ separator=";",
+ prefix="test",
+ threshold=5,
+ floatmode="fixed",
+ suffix="?",
+ legacy="1.13",
+ )
+ np.format_float_scientific(1, precision=5)
+ np.format_float_positional(1, trim="k")
+ np.array_repr(AR)
+ np.array_str(AR)
diff --git a/numpy/typing/tests/data/reveal/arrayprint.py b/numpy/typing/tests/data/reveal/arrayprint.py
new file mode 100644
index 000000000..e797097eb
--- /dev/null
+++ b/numpy/typing/tests/data/reveal/arrayprint.py
@@ -0,0 +1,19 @@
+from typing import Any, Callable
+import numpy as np
+
+AR: np.ndarray[Any, Any]
+func_float: Callable[[np.floating[Any]], str]
+func_int: Callable[[np.integer[Any]], str]
+
+reveal_type(np.get_printoptions()) # E: TypedDict
+reveal_type(np.array2string( # E: str
+ AR, formatter={'float_kind': func_float, 'int_kind': func_int}
+))
+reveal_type(np.format_float_scientific(1.0)) # E: str
+reveal_type(np.format_float_positional(1)) # E: str
+reveal_type(np.array_repr(AR)) # E: str
+reveal_type(np.array_str(AR)) # E: str
+
+reveal_type(np.printoptions()) # E: contextlib._GeneratorContextManager
+with np.printoptions() as dct:
+ reveal_type(dct) # E: TypedDict