summaryrefslogtreecommitdiff
path: root/numpy/_globals.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/_globals.py')
-rw-r--r--numpy/_globals.py40
1 files changed, 39 insertions, 1 deletions
diff --git a/numpy/_globals.py b/numpy/_globals.py
index 0b715c870..c88874725 100644
--- a/numpy/_globals.py
+++ b/numpy/_globals.py
@@ -15,8 +15,11 @@ That was not the case when the singleton classes were defined in the numpy
motivated this module.
"""
+import enum
+
__ALL__ = [
- 'ModuleDeprecationWarning', 'VisibleDeprecationWarning', '_NoValue'
+ 'ModuleDeprecationWarning', 'VisibleDeprecationWarning',
+ '_NoValue', '_CopyMode'
]
@@ -89,3 +92,38 @@ class _NoValueType:
_NoValue = _NoValueType()
+
+
+class _CopyMode(enum.Enum):
+ """
+ An enumeration for the copy modes supported
+ by numpy.copy() and numpy.array(). The following three modes are supported,
+
+ - ALWAYS: This means that a deep copy of the input
+ array will always be taken.
+ - IF_NEEDED: This means that a deep copy of the input
+ array will be taken only if necessary.
+ - NEVER: This means that the deep copy will never be taken.
+ If a copy cannot be avoided then a `ValueError` will be
+ raised.
+
+ Note that the buffer-protocol could in theory do copies. NumPy currently
+ assumes an object exporting the buffer protocol will never do this.
+ """
+
+ ALWAYS = True
+ IF_NEEDED = False
+ NEVER = 2
+
+ def __bool__(self):
+ # For backwards compatiblity
+ if self == _CopyMode.ALWAYS:
+ return True
+
+ if self == _CopyMode.IF_NEEDED:
+ return False
+
+ raise ValueError(f"{self} is neither True nor False.")
+
+
+_CopyMode.__module__ = 'numpy'