Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/check-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-python@v6
- uses: actions/setup-python@v7
with:
python-version: "3.10"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-python@v6
- uses: actions/setup-python@v7
with:
python-version: "3.12"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-python@v6
- uses: actions/setup-python@v7
with:
python-version: "3.10"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@master
with:
fetch-depth: 1
- uses: actions/setup-python@v6
- uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/warnings-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@master
with:
fetch-depth: 1
- uses: actions/setup-python@v6
- uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
Expand Down
2 changes: 1 addition & 1 deletion src/hmf/cosmology/cosmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def cosmo_model(self, val):
return get_cosmo(val)

if not isinstance(val, FLRW):
raise ValueError("cosmo_model must be an instance of astropy.cosmology.FLRW")
raise TypeError("cosmo_model must be an instance of astropy.cosmology.FLRW")
return val

@_cache.parameter("param")
Expand Down
6 changes: 4 additions & 2 deletions src/hmf/cosmology/growth_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def ode(a, y):
D = sol["y"][0, :]

if (sol["status"] != 0) or (D.shape[0] != a.shape[0]):
raise Exception("The calculation of the growth factor failed.")
raise RuntimeError("The calculation of the growth factor failed.")

return (Spline(self._lna, np.log(D)), Spline(D, self._zvec))

Expand Down Expand Up @@ -692,7 +692,9 @@ class GenMFGrowth(BaseGrowthFactor):

def _validate_assumptions(self, z):
if not isinstance(self.cosmo, cosmology.LambdaCDM):
raise ValueError(
# Kept as ValueError (not TypeError): part of the public API contract,
# asserted verbatim by tests/test_growth.py::test_unsupported_cosmo.
raise ValueError( # noqa: TRY004
"The GenMFGrowth factor is only accurate with a cosmological constant. "
"Consider using the ODEGrowthFactor instead."
)
Expand Down
7 changes: 5 additions & 2 deletions src/hmf/density_field/transfer_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

if not isinstance(self.cosmo, (cosmology.LambdaCDM, cosmology.wCDM, cosmology.w0waCDM)):
raise ValueError("CAMB will only work with LCDM or wCDM cosmologies")
# Kept as ValueError (not TypeError): part of the public API contract,
# asserted verbatim by
# tests/test_transfer_models.py::test_camb_rejects_non_lcdm_cosmology.
raise ValueError("CAMB will only work with LCDM or wCDM cosmologies") # noqa: TRY004

# Save the CAMB object properly for use
# Set the cosmology
Expand Down Expand Up @@ -374,7 +377,7 @@ def __getstate__(self):
stacklevel=2,
)

except Exception:
except (pickle.PicklingError, TypeError):
warnings.warn(f"CAMB key {pk} is not pickle-able.", stacklevel=2)

# Deepcopy self
Expand Down
2 changes: 1 addition & 1 deletion src/hmf/halos/mass_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def fnc(x):
xmin = x_guess / XDELTA_GUESS_FACTORS[i]
xmax = x_guess * XDELTA_GUESS_FACTORS[i]
x = sp.optimize.brentq(fnc, xmin, xmax)
except Exception as e:
except (ValueError, RuntimeError) as e:
warnings.warn(f"raised following error: {e}", stacklevel=2)
i += 1

Expand Down
14 changes: 10 additions & 4 deletions src/hmf/mass_function/fitting_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ class BaseFittingFunction(_framework.Component):
def __init__(
self,
nu2: np.ndarray,
m: None | np.ndarray = None,
m: np.ndarray | None = None,
z: float = 0.0,
n_eff: None | np.ndarray = None,
mass_definition: None | md.BaseMassDefinition = None,
n_eff: np.ndarray | None = None,
mass_definition: md.BaseMassDefinition | None = None,
cosmo: csm.FLRW = csm.Planck15,
delta_c: float = 1.68647,
**model_parameters,
Expand Down Expand Up @@ -1368,7 +1368,13 @@ def __init__(self, **model_parameters):
super().__init__(**model_parameters)

if not isinstance(self.mass_definition, md.SphericalOverdensity):
raise ValueError("The Tinker fitting function is a spherical-overdensity function.")
# Kept as ValueError (not TypeError): part of the public API contract, asserted
# verbatim (via Tinker08/Tinker10, which share this __init__) by
# tests/test_fitting_functions_extra.py::test_tinker08_non_so_raises and
# ::test_tinker10_non_so_raises.
raise ValueError( # noqa: TRY004
"The Tinker fitting function is a spherical-overdensity function."
)
delta_halo = self.mass_definition.halo_overdensity_mean(self.z, self.cosmo)

if delta_halo not in self.delta_virs:
Expand Down
2 changes: 1 addition & 1 deletion src/hmf/mass_function/hmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(
dlog10m: float = 0.01,
hmf_model: str | ff.BaseFittingFunction = ff.Tinker08,
hmf_params: dict[str, Any] | None = None,
mdef_model: None | str | MassDef = None,
mdef_model: str | MassDef | None = None,
mdef_params: dict | None = None,
delta_c: float = 1.68647,
filter_model: str | BaseFilter = TopHat,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ def test_obj_eq_numpy():
def test_obj_eq_dictlike_keys(monkeypatch):
def fake_array_equal(a, b):
if isinstance(a, _DictLike) or isinstance(b, _DictLike):
raise ValueError("boom")
# Kept as ValueError (not TypeError): this exercises the `except ValueError`
# branch in hmf._internals._cache.obj_eq, which only catches ValueError.
raise ValueError("boom") # noqa: TRY004
return np.array_equal(a, b)

monkeypatch.setattr(cache, "array_equal", fake_array_equal)
Expand Down
Loading