Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import mmap
import ctypes as ct
import array as _array
import datetime as dt
import enum
from abc import abstractmethod
from types import EllipsisType, ModuleType, TracebackType, MappingProxyType, GenericAlias
from decimal import Decimal
Expand Down Expand Up @@ -442,6 +441,8 @@ from numpy._core.shape_base import (
unstack,
)

from ._expired_attrs_2_0 import __expired_attributes__ as __expired_attributes__

from numpy.lib import (
scimath as emath,
)
Expand Down Expand Up @@ -505,6 +506,8 @@ from numpy.lib._function_base_impl import (
quantile,
)

from numpy._globals import _CopyMode

from numpy.lib._histograms_impl import (
histogram_bin_edges,
histogram,
Expand Down Expand Up @@ -1184,7 +1187,6 @@ newaxis: Final[None] = None
# not in __all__
__NUMPY_SETUP__: Final[L[False]] = False
__numpy_submodules__: Final[set[LiteralString]] = ...
__expired_attributes__: Final[dict[LiteralString, LiteralString]]
__former_attrs__: Final[_FormerAttrsDict] = ...
__future_scalars__: Final[set[L["bytes", "str", "object"]]] = ...
__array_api_version__: Final[L["2023.12"]] = "2023.12"
Expand Down Expand Up @@ -4912,11 +4914,6 @@ bitwise_right_shift = right_shift
permute_dims = transpose
pow = power

class _CopyMode(enum.Enum):
ALWAYS: L[True]
IF_NEEDED: L[False]
NEVER: L[2]

class errstate:
def __init__(
self,
Expand Down
1 change: 1 addition & 0 deletions numpy/_configtool.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def main() -> None: ...
188 changes: 139 additions & 49 deletions numpy/_core/arrayprint.pyi
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
from collections.abc import Callable
from typing import Any, Literal, TypeAlias, TypedDict, SupportsIndex, type_check_only

# Using a private class is by no means ideal, but it is simply a consequence
# of a `contextlib.context` returning an instance of aforementioned class
from contextlib import _GeneratorContextManager
from typing import Any, Final, Literal, SupportsIndex, TypeAlias, TypedDict, overload, type_check_only

from typing_extensions import deprecated

import numpy as np
from numpy import (
integer,
timedelta64,
datetime64,
floating,
complexfloating,
void,
longdouble,
clongdouble,
)
from numpy._typing import NDArray, _CharLike_co, _FloatLike_co

__all__ = [
"array2string",
"array_repr",
"array_str",
"format_float_positional",
"format_float_scientific",
"get_printoptions",
"printoptions",
"set_printoptions",
]

###

_FloatMode: TypeAlias = Literal["fixed", "unique", "maxprec", "maxprec_equal"]
_LegacyNoStyle: TypeAlias = Literal["1.21", "1.25", "2.1", False]
_Legacy: TypeAlias = Literal["1.13", _LegacyNoStyle]
_Sign: TypeAlias = Literal["-", "+", " "]
_Trim: TypeAlias = Literal["k", ".", "0", "-"]
_ReprFunc: TypeAlias = Callable[[NDArray[Any]], str]

@type_check_only
class _FormatDict(TypedDict, total=False):
bool: Callable[[np.bool], str]
int: Callable[[integer[Any]], str]
timedelta: Callable[[timedelta64], str]
datetime: Callable[[datetime64], str]
float: Callable[[floating[Any]], str]
longfloat: Callable[[longdouble], str]
complexfloat: Callable[[complexfloating[Any, Any]], str]
longcomplexfloat: Callable[[clongdouble], str]
void: Callable[[void], str]
int: Callable[[np.integer], str]
timedelta: Callable[[np.timedelta64], str]
datetime: Callable[[np.datetime64], str]
float: Callable[[np.floating], str]
longfloat: Callable[[np.longdouble], str]
complexfloat: Callable[[np.complexfloating], str]
longcomplexfloat: Callable[[np.clongdouble], str]
void: Callable[[np.void], str]
numpystr: Callable[[_CharLike_co], str]
object: Callable[[object], str]
all: Callable[[object], str]
int_kind: Callable[[integer[Any]], str]
float_kind: Callable[[floating[Any]], str]
complex_kind: Callable[[complexfloating[Any, Any]], str]
int_kind: Callable[[np.integer], str]
float_kind: Callable[[np.floating], str]
complex_kind: Callable[[np.complexfloating], str]
str_kind: Callable[[_CharLike_co], str]

@type_check_only
Expand All @@ -48,10 +58,14 @@ class _FormatOptions(TypedDict):
suppress: bool
nanstr: str
infstr: str
formatter: None | _FormatDict
sign: Literal["-", "+", " "]
formatter: _FormatDict | None
sign: _Sign
floatmode: _FloatMode
legacy: Literal[False, "1.13", "1.21"]
legacy: _Legacy

###

__docformat__: Final = "restructuredtext" # undocumented

def set_printoptions(
precision: None | SupportsIndex = ...,
Expand All @@ -62,37 +76,112 @@ def set_printoptions(
nanstr: None | str = ...,
infstr: None | str = ...,
formatter: None | _FormatDict = ...,
sign: Literal[None, "-", "+", " "] = ...,
floatmode: None | _FloatMode = ...,
sign: _Sign | None = None,
floatmode: _FloatMode | None = None,
*,
legacy: Literal[False, "1.13", "1.21", "1.25", "2.1"] | None = ...,
override_repr: None | Callable[[NDArray[Any]], str] = ...,
legacy: _Legacy | None = None,
override_repr: _ReprFunc | None = None,
) -> None: ...
def get_printoptions() -> _FormatOptions: ...

# public numpy export
@overload # no style
def array2string(
a: NDArray[Any],
max_line_width: None | int = ...,
precision: None | SupportsIndex = ...,
suppress_small: None | bool = ...,
separator: str = ...,
prefix: str = ...,
# NOTE: With the `style` argument being deprecated,
# all arguments between `formatter` and `suffix` are de facto
# keyworld-only arguments
max_line_width: int | None = None,
precision: SupportsIndex | None = None,
suppress_small: bool | None = None,
separator: str = " ",
prefix: str = "",
*,
formatter: None | _FormatDict = ...,
threshold: None | int = ...,
edgeitems: None | int = ...,
sign: Literal[None, "-", "+", " "] = ...,
floatmode: None | _FloatMode = ...,
suffix: str = ...,
legacy: Literal[None, False, "1.13", "1.21"] = ...,
formatter: _FormatDict | None = None,
threshold: int | None = None,
edgeitems: int | None = None,
sign: _Sign | None = None,
floatmode: _FloatMode | None = None,
suffix: str = "",
legacy: _Legacy | None = None,
) -> str: ...
@overload # style=<given> (positional), legacy="1.13"
def array2string(
a: NDArray[Any],
max_line_width: int | None,
precision: SupportsIndex | None,
suppress_small: bool | None,
separator: str,
prefix: str,
style: _ReprFunc,
formatter: _FormatDict | None = None,
threshold: int | None = None,
edgeitems: int | None = None,
sign: _Sign | None = None,
floatmode: _FloatMode | None = None,
suffix: str = "",
*,
legacy: Literal["1.13"],
) -> str: ...
@overload # style=<given> (keyword), legacy="1.13"
def array2string(
a: NDArray[Any],
max_line_width: int | None = None,
precision: SupportsIndex | None = None,
suppress_small: bool | None = None,
separator: str = " ",
prefix: str = "",
*,
style: _ReprFunc,
formatter: _FormatDict | None = None,
threshold: int | None = None,
edgeitems: int | None = None,
sign: _Sign | None = None,
floatmode: _FloatMode | None = None,
suffix: str = "",
legacy: Literal["1.13"],
) -> str: ...
@overload # style=<given> (positional), legacy!="1.13"
@deprecated("'style' argument is deprecated and no longer functional except in 1.13 'legacy' mode")
def array2string(
a: NDArray[Any],
max_line_width: int | None,
precision: SupportsIndex | None,
suppress_small: bool | None,
separator: str,
prefix: str,
style: _ReprFunc,
formatter: _FormatDict | None = None,
threshold: int | None = None,
edgeitems: int | None = None,
sign: _Sign | None = None,
floatmode: _FloatMode | None = None,
suffix: str = "",
*,
legacy: _LegacyNoStyle | None = None,
) -> str: ...
@overload # style=<given> (keyword), legacy="1.13"
@deprecated("'style' argument is deprecated and no longer functional except in 1.13 'legacy' mode")
def array2string(
a: NDArray[Any],
max_line_width: int | None = None,
precision: SupportsIndex | None = None,
suppress_small: bool | None = None,
separator: str = " ",
prefix: str = "",
*,
style: _ReprFunc,
formatter: _FormatDict | None = None,
threshold: int | None = None,
edgeitems: int | None = None,
sign: _Sign | None = None,
floatmode: _FloatMode | None = None,
suffix: str = "",
legacy: _LegacyNoStyle | None = None,
) -> str: ...

def format_float_scientific(
x: _FloatLike_co,
precision: None | int = ...,
unique: bool = ...,
trim: Literal["k", ".", "0", "-"] = ...,
trim: _Trim = "k",
sign: bool = ...,
pad_left: None | int = ...,
exp_digits: None | int = ...,
Expand All @@ -103,7 +192,7 @@ def format_float_positional(
precision: None | int = ...,
unique: bool = ...,
fractional: bool = ...,
trim: Literal["k", ".", "0", "-"] = ...,
trim: _Trim = "k",
sign: bool = ...,
pad_left: None | int = ...,
pad_right: None | int = ...,
Expand All @@ -130,8 +219,9 @@ def printoptions(
nanstr: None | str = ...,
infstr: None | str = ...,
formatter: None | _FormatDict = ...,
sign: Literal[None, "-", "+", " "] = ...,
floatmode: None | _FloatMode = ...,
sign: None | _Sign = None,
floatmode: _FloatMode | None = None,
*,
legacy: Literal[None, False, "1.13", "1.21"] = ...
legacy: _Legacy | None = None,
override_repr: _ReprFunc | None = None,
) -> _GeneratorContextManager[_FormatOptions]: ...
1 change: 1 addition & 0 deletions numpy/_distributor_init.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# intentionally left blank
63 changes: 63 additions & 0 deletions numpy/_expired_attrs_2_0.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from typing import Final, TypedDict, final, type_check_only

@final
@type_check_only
class _ExpiredAttributesType(TypedDict):
geterrobj: str
seterrobj: str
cast: str
source: str
lookfor: str
who: str
fastCopyAndTranspose: str
set_numeric_ops: str
NINF: str
PINF: str
NZERO: str
PZERO: str
add_newdoc: str
add_docstring: str
add_newdoc_ufunc: str
compat: str
safe_eval: str
float_: str
complex_: str
longfloat: str
singlecomplex: str
cfloat: str
longcomplex: str
clongfloat: str
string_: str
unicode_: str
Inf: str
Infinity: str
NaN: str
infty: str
issctype: str
maximum_sctype: str
obj2sctype: str
sctype2char: str
sctypes: str
issubsctype: str
set_string_function: str
asfarray: str
issubclass_: str
tracemalloc_domain: str
mat: str
recfromcsv: str
recfromtxt: str
deprecate: str
deprecate_with_doc: str
disp: str
find_common_type: str
round_: str
get_array_wrap: str
DataSource: str
nbytes: str
byte_bounds: str
compare_chararrays: str
format_parser: str
alltrue: str
sometrue: str

__expired_attributes__: Final[_ExpiredAttributesType] = ...
15 changes: 15 additions & 0 deletions numpy/_globals.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
__all__ = ["_CopyMode", "_NoValue"]

import enum
from typing import Final, final

@final
class _CopyMode(enum.Enum):
ALWAYS = True
IF_NEEDED = False
NEVER = 2

@final
class _NoValueType: ...

_NoValue: Final[_NoValueType] = ...
Loading
Loading