Skip to content
Open
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
1 change: 1 addition & 0 deletions docs/conf.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need/want to run doctests through Sphinx. I assume you added this to enable the .. testsetup:: directive and that pytest supports it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkeryan, I suggest we look together at the root cause and a fix I'd like to propose for that before spending more time on this PR.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"autoapi.extension",
"m2r2",
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
Expand Down
31 changes: 30 additions & 1 deletion src/nitypes/_arguments.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this issue only affect run_unit_tests_oldest_deps.yml? If so, I think disabling doctests on the command line in that workflow file would be a less obtrusive workaround. If --no-doctest-modules doesn't work, try -p no:doctest.

Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,27 @@

# Some of these doctests use types introduced in NumPy 2.0 (np.long and np.ulong) or highlight
# formatting differences between NumPy 1.x and 2.x (e.g. dtype=int32, 1.23 vs. np.float64(1.23)).
__doctest_requires__ = {("arg_to_float", "is_dtype", "validate_dtype"): ["numpy>=2.0"]}
# The following line is commented out as workaround for technical debt #251.
# __doctest_requires__ = {("arg_to_float", "is_dtype", "validate_dtype"): ["numpy>=2.0"]}
# When the technical debt is resolved, uncomment the line above
# and remove testsetup blocks that include comments like the one below:
# # Workaround for technical debt #251: Skip doctest if numpy<2.0
# >>> pytest.skip("requires numpy>=2.0") if version_check else None # doctest: +SKIP


def arg_to_float(
arg_description: str, value: SupportsFloat | None, default_value: float | None = None
) -> float:
"""Convert an argument to a float.

.. testsetup::

# Workaround for technical debt #251: Skip doctest if numpy<2.0
import numpy as np
import pytest
numpy_version = tuple(map(int, np.__version__.split(".")[:2])) < (2, 0)
pytest.skip("requires numpy>=2.0") if numpy_version else None

>>> arg_to_float("xyz", 1.234)
1.234
>>> arg_to_float("xyz", 1234)
Expand Down Expand Up @@ -143,6 +156,14 @@ def is_dtype(dtype: npt.DTypeLike, supported_dtypes: tuple[npt.DTypeLike, ...])

Unlike :any:`numpy.isdtype`, this function supports structured data types.

.. testsetup::

# Workaround for technical debt #251: Skip doctest if numpy<2.0
import numpy as np
import pytest
numpy_version = tuple(map(int, np.__version__.split(".")[:2])) < (2, 0)
pytest.skip("requires numpy>=2.0") if numpy_version else None

>>> is_dtype(np.float64, (np.float64, np.intc, np.long,))
True
>>> is_dtype("float64", (np.float64, np.intc, np.long,))
Expand Down Expand Up @@ -172,6 +193,14 @@ def is_dtype(dtype: npt.DTypeLike, supported_dtypes: tuple[npt.DTypeLike, ...])
def validate_dtype(dtype: npt.DTypeLike, supported_dtypes: tuple[npt.DTypeLike, ...]) -> None:
"""Validate a dtype-like object against a tuple of supported dtype-like objects.

.. testsetup::

# Workaround for technical debt #251: Skip doctest if numpy<2.0
import numpy as np
import pytest
numpy_version = tuple(map(int, np.__version__.split(".")[:2])) < (2, 0)
pytest.skip("requires numpy>=2.0") if numpy_version else None

>>> validate_dtype(np.float64, (np.float64, np.intc, np.long,))
>>> validate_dtype("float64", (np.float64, np.intc, np.long,))
>>> validate_dtype(np.float64, (np.byte, np.short, np.intc, np.int_, np.long, np.longlong))
Expand Down
14 changes: 13 additions & 1 deletion src/nitypes/complex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@

You can construct an array of complex integers from a sequence of tuples using :func:`numpy.array`:

.. testsetup::

# Workaround for technical debt #251: Skip doctest if numpy<2.0
import numpy as np
import pytest
numpy_version = tuple(map(int, np.__version__.split(".")[:2])) < (2, 0)
pytest.skip("requires numpy>=2.0") if numpy_version else None

>>> import numpy as np
>>> np.array([(1, 2), (3, 4)], dtype=ComplexInt32DType)
array([(1, 2), (3, 4)], dtype=[('real', '<i2'), ('imag', '<i2')])
Expand Down Expand Up @@ -127,4 +135,8 @@
from nitypes.complex._dtypes import ComplexInt32Base, ComplexInt32DType

__all__ = ["convert_complex", "ComplexInt32DType", "ComplexInt32Base"]
__doctest_requires__ = {".": ["numpy>=2.0"]}
# The following line is commented out as workaround for technical debt #251.
# __doctest_requires__ = {".": ["numpy>=2.0"]}
# When the technical debt is resolved, uncomment the line above
# and remove testsetup blocks that include comments like the one below:
# # Workaround for technical debt #251: Skip doctest if numpy<2.0