Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/numpy/_globals.py
7771 views
"""1Module defining global singleton classes.23This module raises a RuntimeError if an attempt to reload it is made. In that4way the identities of the classes defined here are fixed and will remain so5even if numpy itself is reloaded. In particular, a function like the following6will still work correctly after numpy is reloaded::78def foo(arg=np._NoValue):9if arg is np._NoValue:10...1112That was not the case when the singleton classes were defined in the numpy13``__init__.py`` file. See gh-7844 for a discussion of the reload problem that14motivated this module.1516"""17import enum1819__ALL__ = [20'ModuleDeprecationWarning', 'VisibleDeprecationWarning',21'_NoValue', '_CopyMode'22]232425# Disallow reloading this module so as to preserve the identities of the26# classes defined here.27if '_is_loaded' in globals():28raise RuntimeError('Reloading numpy._globals is not allowed')29_is_loaded = True303132class ModuleDeprecationWarning(DeprecationWarning):33"""Module deprecation warning.3435The nose tester turns ordinary Deprecation warnings into test failures.36That makes it hard to deprecate whole modules, because they get37imported by default. So this is a special Deprecation warning that the38nose tester will let pass without making tests fail.3940"""414243ModuleDeprecationWarning.__module__ = 'numpy'444546class VisibleDeprecationWarning(UserWarning):47"""Visible deprecation warning.4849By default, python will not show deprecation warnings, so this class50can be used when a very visible warning is helpful, for example because51the usage is most likely a user bug.5253"""545556VisibleDeprecationWarning.__module__ = 'numpy'575859class _NoValueType:60"""Special keyword value.6162The instance of this class may be used as the default value assigned to a63keyword if no other obvious default (e.g., `None`) is suitable,6465Common reasons for using this keyword are:6667- A new keyword is added to a function, and that function forwards its68inputs to another function or method which can be defined outside of69NumPy. For example, ``np.std(x)`` calls ``x.std``, so when a ``keepdims``70keyword was added that could only be forwarded if the user explicitly71specified ``keepdims``; downstream array libraries may not have added72the same keyword, so adding ``x.std(..., keepdims=keepdims)``73unconditionally could have broken previously working code.74- A keyword is being deprecated, and a deprecation warning must only be75emitted when the keyword is used.7677"""78__instance = None79def __new__(cls):80# ensure that only one instance exists81if not cls.__instance:82cls.__instance = super().__new__(cls)83return cls.__instance8485# needed for python 2 to preserve identity through a pickle86def __reduce__(self):87return (self.__class__, ())8889def __repr__(self):90return "<no value>"919293_NoValue = _NoValueType()949596class _CopyMode(enum.Enum):97"""98An enumeration for the copy modes supported99by numpy.copy() and numpy.array(). The following three modes are supported,100101- ALWAYS: This means that a deep copy of the input102array will always be taken.103- IF_NEEDED: This means that a deep copy of the input104array will be taken only if necessary.105- NEVER: This means that the deep copy will never be taken.106If a copy cannot be avoided then a `ValueError` will be107raised.108109Note that the buffer-protocol could in theory do copies. NumPy currently110assumes an object exporting the buffer protocol will never do this.111"""112113ALWAYS = True114IF_NEEDED = False115NEVER = 2116117def __bool__(self):118# For backwards compatiblity119if self == _CopyMode.ALWAYS:120return True121122if self == _CopyMode.IF_NEEDED:123return False124125raise ValueError(f"{self} is neither True nor False.")126127128_CopyMode.__module__ = 'numpy'129130131