Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a9f5c70
Messing around trying to find a workable approach.
kyleaoman Mar 21, 2025
1151704
Improvements to a test.
kyleaoman Mar 21, 2025
d268816
Tidy up and ensure tests pass.
kyleaoman Mar 22, 2025
3843127
Fix typo.
kyleaoman Oct 10, 2025
efbfb22
Merge branch 'master' into support_rmul
kyleaoman Oct 10, 2025
d2acaa9
Run formatter.
kyleaoman Oct 10, 2025
6e44ef3
Depend on unyt main branch for testing.
kyleaoman Oct 10, 2025
ce72da3
Fix botched merge and clean up tests based on notes from past self.
kyleaoman Oct 10, 2025
a4761a5
Run black...
kyleaoman Oct 10, 2025
5b8856c
Merge branch 'master' into support_rmul
kyleaoman Oct 25, 2025
54851cd
Run formatter.
kyleaoman Oct 25, 2025
cef1925
Merge branch 'master' into support_rmul
kyleaoman Oct 27, 2025
40cf579
Bugfix.
kyleaoman Oct 27, 2025
8f5dab2
Fill out docstrings and type hints.
kyleaoman Oct 27, 2025
c3723dc
Temporarily point to unyt main branch as dependency while waiting for…
kyleaoman Jan 13, 2026
cd7ecf6
Add regression test.
kyleaoman Jan 13, 2026
32a2e8e
Patch works in numpy2.3.4
kyleaoman Jan 13, 2026
fe79d38
Patch works in numpy 2.4.1
kyleaoman Jan 13, 2026
949bb38
Compatibility fixes for unyt 3.1.0 and numpy 2.4.1
kyleaoman Jan 13, 2026
54ade28
More version-dependent cases.
kyleaoman Jan 13, 2026
5907ab1
Merge branch 'support_rmul' into unyt3_1_0
kyleaoman Jan 13, 2026
26b6522
Merge branch 'fix_average' into unyt3_1_0
kyleaoman Jan 13, 2026
80ada0d
Make a single source of truth for dependencies.
kyleaoman Jan 13, 2026
5bb3bf2
Fix mismatched extra deps name.
kyleaoman Jan 13, 2026
c8a423b
Install from repo, not pypi, on RTD.
kyleaoman Jan 14, 2026
4be32cd
Pin to unyt 3.1.0, tentatively astropy 7.0
kyleaoman Jan 15, 2026
5ef628e
No astropy7 in py3.10,pin to >6?
kyleaoman Jan 15, 2026
545e6a8
Be deliberate about when latest & stable versions of docs are linked to.
kyleaoman Jan 23, 2026
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
14 changes: 1 addition & 13 deletions .github/workflows/lint_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,10 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip
uses: actions/cache@v4
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ runner.os }}-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f optional_requirements.txt ]; then pip install -r optional_requirements.txt; fi
pip install -e .
pip install -e .[dev]
- name: Test with pytest
run: |
pytest
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install setuptools wheel build
pip install -r requirements.txt
pip install .
- name: Build
run: |
Expand Down
10 changes: 1 addition & 9 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ build:
python: "3.12"
jobs:
post_create_environment:
- python3 -m pip install swiftsimio
- python3 -m pip install -r optional_requirements.txt
- python3 -m pip install .[docs]

# Build documentation in the "docs/" directory with Sphinx
sphinx:
Expand All @@ -22,11 +21,4 @@ sphinx:
formats:
- pdf
- epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt

4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Documentation

The API documentation is built automatically from the docstrings of classes, functions, etc. in the source files. These follow the NumPy-style format. All public (i.e. not starting in `_`) modules, functions, classes, methods, etc. should have an appropriate docstring. Tests should also have descriptive docstrings, but full descriptions (e.g. of all parameters) are not required.

In addition to this there is "narrative documentation" that should describe the features of the code. The docs are built with `sphinx` and use the "ReadTheDocs" theme. If you have the dependencies installed (check `/docs/requirements.txt`) you can build the documentation locally with `make html` in the `/docs` directory. Opening the `/docs/index.html` file with a browser will then allow you to browse the documentation and check your contributions.
In addition to this there is "narrative documentation" that should describe the features of the code. The docs are built with `sphinx` and use the "ReadTheDocs" theme. If you have the dependencies installed (check `pyproject.toml` or use `pip install -e .[docs]` in the project root directory) you can build the documentation locally with `make html` in the `/docs` directory. Opening the `/docs/build/index.html` file with a browser will then allow you to browse the documentation and check your contributions.

Docstrings
----------

Ruff currently has limited support for [numpydoc](https://numpydoc.readthedocs.io/en/latest/index.html)-style docstrings. To run additional checks on docstrings use `numpydoc lint **/*.py` in the same directory as the `pyproject.toml` file. As more style rules become supported by `ruff` this will hopefully be phased out.
Ruff currently has limited support for [numpydoc](https://numpydoc.readthedocs.io)-style docstrings. To run additional checks on docstrings use `numpydoc lint **/*.py` in the same directory as the `pyproject.toml` file. As more style rules become supported by `ruff` this will hopefully be phased out.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SWIFTsimIO
:target: https://github.com/SWIFTSIM/swiftsimio/actions/workflows/lint_and_test.yml
:alt: Build status
.. |Documentation status| image:: https://readthedocs.org/projects/swiftsimio/badge/?version=latest
:target: https://swiftsimio.readthedocs.io/en/latest/?badge=latest
:target: https://swiftsimio.readthedocs.io
:alt: Documentation status
.. |JOSS| image:: https://joss.theoj.org/papers/e85c85f49b99389d98f9b6d81f090331/status.svg
:target: https://joss.theoj.org/papers/e85c85f49b99389d98f9b6d81f090331
Expand Down
4 changes: 0 additions & 4 deletions docs/requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def setup(app): # numpydoc ignore=GL08
numba=("https://numba.readthedocs.io/en/stable/", None),
unyt=("https://unyt.readthedocs.io/en/stable/", None),
scipy=("https://docs.scipy.org/doc/scipy/", None),
swiftgalaxy=("https://swiftsimio.readthedocs.io/en/latest/", None),
swiftgalaxy=("https://swiftgalaxy.readthedocs.io/en/stable/", None),
velociraptor=("https://velociraptor-python.readthedocs.io/en/latest/", None),
astropy=("https://docs.astropy.org/en/stable/", None),
)
11 changes: 2 additions & 9 deletions docs/source/getting_started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,12 @@ To set up the code for development, first clone the latest master from GitHub:

git clone https://github.com/SWIFTSIM/swiftsimio.git

and install with ``pip`` using the ``-e`` ("editable") flag,
and install with ``pip`` using the ``-e`` ("editable") flag, and specifying optional dependencies for development and building the documentation:

.. code-block::

cd swiftsimio
pip install -e .

Then install the optioanl dependencies for the code and the documentation:

.. code-block::

pip install -r optional_requirements.txt
pip install -r docs/requirements.txt
pip install -e .[dev,docs]

.. include:: ../../../README.rst
:start-after: COMMUNITY_START_LABEL
Expand Down
2 changes: 1 addition & 1 deletion docs/source/soap/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ swiftgalaxy

The :mod:`swiftgalaxy` companion package to :mod:`swiftsimio` offers further integration with halo catalogues in SOAP, Caesar and Velociraptor formats (so far). It greatly simplifies efficient loading of particles belonging to an object from a catalogue, and additional tools that are useful when working with a galaxy or other localized collection of particles. Refer to the `swiftgalaxy documentation`_ for details.

.. _swiftgalaxy documentation: https://swiftgalaxy.readthedocs.io/en/latest/
.. _swiftgalaxy documentation: https://swiftgalaxy.readthedocs.io
7 changes: 0 additions & 7 deletions optional_requirements.txt

This file was deleted.

25 changes: 22 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,40 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"astropy>=5.0",
"astropy>=6.0",
"numpy>=2.1.0",
"h5py",
"unyt>=3.0.4",
"unyt>=3.1.0",
"numba>=0.50.0",
]

[project.urls]
"Homepage" = "https://github.com/SWIFTSIM/swiftsimio"
"Bug Tracker" = "https://github.com/SWIFTSIM/swiftsimio/issues"
"Documentation" = "https://swiftsimio.readthedocs.io/en/latest"
"Documentation" = "https://swiftsimio.readthedocs.io"

[project.scripts]
swiftsnap = "swiftsimio.swiftsnap:swiftsnap"

[project.optional-dependencies]
dev = [
"pytest",
"ruff",
"numpydoc",
"matplotlib",
"scipy",
"wily",
]
docs = [
"sphinx",
"sphinx-rtd-theme",
"recommonmark",
"sphinx_design",
]
all = [
"swiftsimio[dev,docs]"
]

[tool.ruff]
exclude = ["docs/source/conf.py"]
line-length = 88
Expand Down
5 changes: 0 additions & 5 deletions requirements.txt

This file was deleted.

82 changes: 43 additions & 39 deletions swiftsimio/_array_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
linalg_eigvalsh as unyt_linalg_eigvalsh,
savetxt as unyt_savetxt,
fill_diagonal as unyt_fill_diagonal,
isin as unyt_isin,
place as unyt_place,
put as unyt_put,
put_along_axis as unyt_put_along_axis,
Expand All @@ -115,9 +114,13 @@
array_repr as unyt_array_repr,
linalg_outer as unyt_linalg_outer,
trapezoid as unyt_trapezoid,
isin as unyt_in1d,
isin as unyt_isin,
take as unyt_take,
)
from importlib.metadata import version
from packaging.version import Version

NUMPY_VERSION = Version(version("numpy"))

_HANDLED_FUNCTIONS = {}

Expand Down Expand Up @@ -1271,39 +1274,8 @@ def wrapper(*args: tuple[Any], **kwargs: dict[str, Any]) -> Callable:


@implements(np.array2string)
def array2string( # noqa numpydoc ignore=GL08
a, # noqa: ANN001
max_line_width=None, # noqa: ANN001
precision=None, # noqa: ANN001
suppress_small=None, # noqa: ANN001
separator=" ", # noqa: ANN001
prefix="", # noqa: ANN001
style=np._NoValue, # noqa: ANN001
formatter=None, # noqa: ANN001
threshold=None, # noqa: ANN001
edgeitems=None, # noqa: ANN001
sign=None, # noqa: ANN001
floatmode=None, # noqa: ANN001
suffix="", # noqa: ANN001
*,
legacy=None, # noqa: ANN001
):
res = unyt_array2string(
a,
max_line_width=max_line_width,
precision=precision,
suppress_small=suppress_small,
separator=separator,
prefix=prefix,
style=style,
formatter=formatter,
threshold=threshold,
edgeitems=edgeitems,
sign=sign,
floatmode=floatmode,
suffix=suffix,
legacy=legacy,
)
def array2string(a, *args, **kwargs): # noqa numpydoc ignore=GL08
res = unyt_array2string(a, *args, **kwargs)
if a.comoving:
append = " (comoving)"
elif a.comoving is False:
Expand Down Expand Up @@ -2262,14 +2234,46 @@ def trapezoid(y, x=None, dx=1.0, axis=-1): # noqa numpydoc ignore=GL08
return _return_helper(res, helper_result, ret_cf)


implements(np.in1d)(_default_comparison_wrapper(unyt_in1d))
implements(np.isin)(_default_comparison_wrapper(unyt_isin))
implements(np.take)(_default_unary_wrapper(unyt_take, _preserve_cosmo_factor))

# Now we wrap functions that unyt does not handle explicitly:

implements(np.average)(
_propagate_cosmo_array_attributes_to_result(np.average._implementation)
)

@implements(np.average)
def average(a, axis=None, weights=None, returned=False, *, keepdims=np._NoValue): # noqa numpydoc ignore=GL08
# Average suffered from a bug
# (https://github.com/SWIFTSIM/swiftsimio/issues/285)
# Correct results depend on unyt>=3.1.0
# (https://github.com/yt-project/unyt/pull/611)
# There is also a fix in numpy>=3.4.1
# (https://github.com/numpy/numpy/pull/30522)
# that means we no longer need any special handling here, but to support older
# versions we need a patch.
helper_result = _prepare_array_func_args(
a, axis=axis, weights=weights, returned=returned, keepdims=keepdims
)
if NUMPY_VERSION < Version("2.4.1"):
from unyt._array_functions import average as super_average

else:
super_average = np.average._implementation

res = super_average(
a, axis=axis, weights=weights, returned=returned, keepdims=keepdims
)
ret_cf_avg = _preserve_cosmo_factor(helper_result["cfs"][0])
if returned:
avg, wsum = res
ret_cf_wsum = _preserve_cosmo_factor(helper_result["kw_cfs"]["weights"])
return (
_return_helper(avg, helper_result, ret_cf_avg),
_return_helper(wsum, helper_result, ret_cf_wsum),
)
else:
return _return_helper(res, helper_result, ret_cf_avg)


implements(np.max)(_propagate_cosmo_array_attributes_to_result(np.max._implementation))
implements(np.min)(_propagate_cosmo_array_attributes_to_result(np.min._implementation))
implements(np.mean)(
Expand Down
Loading