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

Skip to content

Commit ebedc68

Browse files
authored
Merge pull request #26173 from charris/backport-26172
DOC, TST: make ``numpy.version`` officially public
2 parents 7586852 + 589390a commit ebedc68

File tree

5 files changed

+64
-8
lines changed

5 files changed

+64
-8
lines changed

doc/source/reference/module_structure.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Special-purpose namespaces
3535
- :ref:`numpy.emath <routines.emath>` - mathematical functions with automatic domain
3636
- :ref:`numpy.lib <routines.lib>` - utilities & functionality which do not fit the main namespace
3737
- :ref:`numpy.rec <routines.rec>` - record arrays (largely superseded by dataframe libraries)
38+
- :ref:`numpy.version <routines.version>` - small module with more detailed version info
3839

3940
Legacy namespaces
4041
=================
@@ -67,6 +68,7 @@ and/or this code is deprecated or isn't reliable.
6768
numpy.emath <routines.emath>
6869
numpy.lib <routines.lib>
6970
numpy.rec <routines.rec>
71+
numpy.version <routines.version>
7072
numpy.char <routines.char>
7173
numpy.distutils <distutils>
7274
numpy.f2py <../f2py/index>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.. currentmodule:: numpy.version
2+
3+
.. _routines.version:
4+
5+
*******************
6+
Version information
7+
*******************
8+
9+
The ``numpy.version`` submodule includes several constants that expose more
10+
detailed information about the exact version of the installed ``numpy``
11+
package:
12+
13+
.. data:: version
14+
15+
Version string for the installed package - matches ``numpy.__version__``.
16+
17+
.. data:: full_version
18+
19+
Version string - the same as ``numpy.version.version``.
20+
21+
.. data:: short_version
22+
23+
Version string without any local build identifiers.
24+
25+
.. rubric:: Examples
26+
27+
>>> np.__version__
28+
'2.1.0.dev0+git20240319.2ea7ce0' # may vary
29+
>>> np.version.short_version
30+
'2.1.0.dev0' # may vary
31+
32+
.. data:: git_revision
33+
34+
String containing the git hash of the commit from which ``numpy`` was built.
35+
36+
.. data:: release
37+
38+
``True`` if this version is a ``numpy`` release, ``False`` if a dev version.

numpy/_build_utils/gitversion.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def git_version(version):
7070

7171
# For NumPy 2.0, this should only have one field: `version`
7272
template = textwrap.dedent(f'''
73+
"""
74+
Module to expose more detailed version info for the installed `numpy`
75+
"""
7376
version = "{version}"
7477
__version__ = version
7578
full_version = version

numpy/tests/test_numpy_version.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,16 @@ def test_short_version():
3939
else:
4040
assert_(np.__version__.split("+")[0] == np.version.short_version,
4141
"short_version mismatch in development version")
42+
43+
44+
def test_version_module():
45+
contents = set([s for s in dir(np.version) if not s.startswith('_')])
46+
expected = set([
47+
'full_version',
48+
'git_revision',
49+
'release',
50+
'short_version',
51+
'version',
52+
])
53+
54+
assert contents == expected

numpy/tests/test_public_api.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ def test_NPY_NO_EXPORT():
114114
"f2py",
115115
"fft",
116116
"lib",
117-
"lib.format", # was this meant to be public?
117+
"lib.array_utils",
118+
"lib.format",
119+
"lib.introspect",
118120
"lib.mixins",
119-
"lib.recfunctions",
121+
"lib.npyio",
122+
"lib.recfunctions", # note: still needs cleaning, was forgotten for 2.0
120123
"lib.scimath",
121124
"lib.stride_tricks",
122-
"lib.npyio",
123-
"lib.introspect",
124-
"lib.array_utils",
125125
"linalg",
126126
"ma",
127127
"ma.extras",
@@ -134,11 +134,12 @@ def test_NPY_NO_EXPORT():
134134
"polynomial.legendre",
135135
"polynomial.polynomial",
136136
"random",
137+
"strings",
137138
"testing",
138139
"testing.overrides",
139140
"typing",
140141
"typing.mypy_plugin",
141-
"version" # Should be removed for NumPy 2.0
142+
"version",
142143
]]
143144
if sys.version_info < (3, 12):
144145
PUBLIC_MODULES += [
@@ -158,7 +159,6 @@ def test_NPY_NO_EXPORT():
158159
"numpy.char",
159160
"numpy.emath",
160161
"numpy.rec",
161-
"numpy.strings",
162162
]
163163

164164

@@ -535,7 +535,7 @@ def test_core_shims_coherence():
535535
# no need to add it to np.core
536536
if (
537537
member_name.startswith("_")
538-
or member_name == "tests"
538+
or member_name in ["tests", "strings"]
539539
or f"numpy.{member_name}" in PUBLIC_ALIASED_MODULES
540540
):
541541
continue

0 commit comments

Comments
 (0)