Skip to content

Commit 728c69a

Browse files
committed
Support setting the version to the draft version of the standard
1 parent dec8c22 commit 728c69a

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

array_api_strict/_flags.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
"2023.12",
2525
)
2626

27+
draft_version = "2024.12"
28+
2729
API_VERSION = default_version = "2023.12"
2830

2931
BOOLEAN_INDEXING = True
@@ -70,8 +72,8 @@ def set_array_api_strict_flags(
7072
----------
7173
api_version : str, optional
7274
The version of the standard to use. Supported versions are:
73-
``{supported_versions}``. The default version number is
74-
``{default_version!r}``.
75+
``{supported_versions}``, plus the draft version ``{draft_version}``.
76+
The default version number is ``{default_version!r}``.
7577
7678
Note that 2021.12 is supported, but currently gives the same thing as
7779
2022.12 (except that the fft extension will be disabled).
@@ -134,10 +136,12 @@ def set_array_api_strict_flags(
134136
global API_VERSION, BOOLEAN_INDEXING, DATA_DEPENDENT_SHAPES, ENABLED_EXTENSIONS
135137

136138
if api_version is not None:
137-
if api_version not in supported_versions:
139+
if api_version not in [*supported_versions, draft_version]:
138140
raise ValueError(f"Unsupported standard version {api_version!r}")
139141
if api_version == "2021.12":
140142
warnings.warn("The 2021.12 version of the array API specification was requested but the returned namespace is actually version 2022.12", stacklevel=2)
143+
if api_version == draft_version:
144+
warnings.warn(f"The {draft_version} version of the array API specification is in draft status. Not all features are implemented in array_api_strict, and behaviors are subject to change before the final standard release.")
141145
API_VERSION = api_version
142146
array_api_strict.__array_api_version__ = API_VERSION
143147

@@ -169,6 +173,7 @@ def set_array_api_strict_flags(
169173
supported_versions=supported_versions,
170174
default_version=default_version,
171175
default_extensions=default_extensions,
176+
draft_version=draft_version,
172177
)
173178

174179
def get_array_api_strict_flags():

array_api_strict/tests/test_array_object.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,12 @@ def test_array_namespace():
440440
assert a.__array_namespace__(api_version="2021.12") is array_api_strict
441441
assert array_api_strict.__array_api_version__ == "2021.12"
442442

443+
with pytest.warns(UserWarning):
444+
assert a.__array_namespace__(api_version="2024.12") is array_api_strict
445+
assert array_api_strict.__array_api_version__ == "2024.12"
446+
443447
pytest.raises(ValueError, lambda: a.__array_namespace__(api_version="2021.11"))
444-
pytest.raises(ValueError, lambda: a.__array_namespace__(api_version="2024.12"))
448+
pytest.raises(ValueError, lambda: a.__array_namespace__(api_version="2025.12"))
445449

446450
def test_iter():
447451
pytest.raises(TypeError, lambda: iter(asarray(3)))

array_api_strict/tests/test_flags.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ def test_flags_api_version_2023_12():
9999
'enabled_extensions': ('linalg', 'fft'),
100100
}
101101

102+
def test_flags_api_version_2024_12():
103+
# Make sure setting the version to 2024.12 issues a warning.
104+
with pytest.warns(UserWarning) as record:
105+
set_array_api_strict_flags(api_version='2024.12')
106+
assert len(record) == 1
107+
assert '2024.12' in str(record[0].message)
108+
assert 'draft' in str(record[0].message)
109+
flags = get_array_api_strict_flags()
110+
assert flags == {
111+
'api_version': '2024.12',
112+
'boolean_indexing': True,
113+
'data_dependent_shapes': True,
114+
'enabled_extensions': ('linalg', 'fft'),
115+
}
116+
102117
def test_setting_flags_invalid():
103118
# Test setting flags with invalid values
104119
pytest.raises(ValueError, lambda:

0 commit comments

Comments
 (0)