Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress or fix warnings #1272

Merged
merged 5 commits into from
Jul 29, 2024
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
3 changes: 2 additions & 1 deletion pyaerocom/io/read_ebas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,13 +1516,14 @@ def _check_correct_freq(self, file, freq_ebas):
if TsType(freq_ebas).check_match_total_seconds(most_common_dt):
return freq_ebas

logger.warning(
logger.info(
f"Detected wrong frequency {freq_ebas}. Trying to infer the correct frequency..."
)
try:
freq = TsType.from_total_seconds(most_common_dt)
return str(freq)
except TemporalResolutionError:
logger.warning("Unable to infer the correct frequency...")
raise TemporalResolutionError(
f"Failed to derive correct sampling frequency in {file.file_name}. "
f"Most common meas period (stop_meas - start_meas) in file is "
Expand Down
9 changes: 8 additions & 1 deletion pyaerocom/stats/implementations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import numpy as np
from scipy.stats import kendalltau, spearmanr
from scipy.stats import ConstantInputWarning, kendalltau, spearmanr

from pyaerocom.mathutils import corr, sum

from .._warnings import ignore_warnings


def stat_R(data: np.ndarray, ref_data: np.ndarray, weights: np.ndarray | None) -> np.float64:
"""
Expand Down Expand Up @@ -45,6 +47,7 @@ def stat_mab(data: np.ndarray, ref_data: np.ndarray, weights: np.ndarray | None)
return sum(np.abs(difference)) / len(data)


@ignore_warnings(RuntimeWarning, "invalid value encountered in divide")
def stat_mnmb(data: np.ndarray, ref_data: np.ndarray, weights: np.ndarray | None) -> np.float64:
"""
Modified normalised mean bias implementation.
Expand All @@ -56,6 +59,7 @@ def stat_mnmb(data: np.ndarray, ref_data: np.ndarray, weights: np.ndarray | None
return 2 / len(data) * sum(difference / (data + ref_data))


@ignore_warnings(RuntimeWarning, "invalid value encountered in divide")
def stat_fge(data: np.ndarray, ref_data: np.ndarray, weights: np.ndarray | None) -> np.float64:
"""
Fractional gross error implementation.
Expand All @@ -67,6 +71,9 @@ def stat_fge(data: np.ndarray, ref_data: np.ndarray, weights: np.ndarray | None)
return 2 / len(data) * sum(np.abs(difference / (data + ref_data)), weights=weights)


@ignore_warnings(
ConstantInputWarning, "An input array is constant; the correlation coefficient is not defined."
)
def stat_R_spearman(
data: np.ndarray, ref_data: np.ndarray, weights: np.ndarray | None
) -> np.float64:
Expand Down
2 changes: 2 additions & 0 deletions tests/cams2_83/test_cams2_83_cli_mos.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest
from typer.testing import CliRunner

from pyaerocom._warnings import ignore_warnings
from pyaerocom.scripts.cams2_83.cli_mos import app

runner = CliRunner()
Expand Down Expand Up @@ -71,6 +72,7 @@ def test_eval_mos_standard(tmp_path: Path, coldata_mos: Path, caplog):
assert "Done Running Statistics (MOS)" in caplog.text


@ignore_warnings(RuntimeWarning, "invalid value encountered in divide")
@pytest.mark.usefixtures("fake_ExperimentProcessor", "reset_cachedir")
def test_eval_mos_medianscores(tmp_path: Path, coldata_mos: Path, caplog):
options = f"season 2024-03-01 2024-03-05 --data-path {tmp_path} --coldata-path {coldata_mos} --cache {tmp_path} --id mos-colocated-data --name 'Test'"
Expand Down
19 changes: 19 additions & 0 deletions tests/io/test_helpers_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest
from scipy.constants import Avogadro

from pyaerocom._warnings import ignore_warnings
from pyaerocom.io.helpers_units import (
mass_to_nr_molecules,
nr_molecules_to_mass,
Expand Down Expand Up @@ -52,6 +53,12 @@ def test_unitconv_sfc_conc(dummy_data):
assert np.all(result == pytest.approx(1.99796663, 1e-4))


@ignore_warnings(
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a TODO: Change to update pandas without breaking other tests

FutureWarning,
"'M' is deprecated and will be removed in a future version, please use 'ME' instead.",
)
# TODO: The above warning is ignored because the old-dependency CI tests don't currently
# support ME. Once we bump dependencies so we can change over, this should be removed.
def test_unitconv_wet_depo_bck(dummy_data):
time = pd.Series(pd.date_range(start="2000-01-01", periods=len(dummy_data), freq="M"))
result = unitconv_wet_depo_bck(dummy_data, time)
Expand All @@ -60,6 +67,12 @@ def test_unitconv_wet_depo_bck(dummy_data):
) # sufficent to check length b/c wet depo will change month-to-month


@ignore_warnings(
FutureWarning,
"'M' is deprecated and will be removed in a future version, please use 'ME' instead.",
)
# TODO: The above warning is ignored because the old-dependency CI tests don't currently
# support ME. Once we bump dependencies so we can change over, this should be removed.
def test_unitconv_wet_depo_from_emep(dummy_data):
time = pd.Series(pd.date_range(start="2000-01-01", periods=len(dummy_data), freq="M"))
result = unitconv_wet_depo_from_emep(dummy_data, time)
Expand All @@ -68,6 +81,12 @@ def test_unitconv_wet_depo_from_emep(dummy_data):
) # sufficent to check length b/c wet depo will change month-to-month


@ignore_warnings(
FutureWarning,
"'M' is deprecated and will be removed in a future version, please use 'ME' instead.",
)
# TODO: The above warning is ignored because the old-dependency CI tests don't currently
# support ME. Once we bump dependencies so we can change over, this should be removed.
def test_unitconv_wet_depo_from_emep_time_not_pandas_series(dummy_data):
time = pd.date_range(start="2000-01-01", periods=len(dummy_data), freq="M")
result = unitconv_wet_depo_from_emep(dummy_data, time)
Expand Down
6 changes: 2 additions & 4 deletions tests/stats/mda8/test_mda8.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import xarray as xr

from pyaerocom.colocation.colocated_data import ColocatedData
from pyaerocom.colocation.colocation_3d import ColocatedDataLists
from pyaerocom.stats.mda8.mda8 import (
_calc_mda8,
_daily_max,
_rolling_average_8hr,
mda8_colocated_data,
)
from tests.fixtures.collocated_data import coldata


@pytest.fixture
Expand All @@ -27,7 +25,7 @@ def test_data(time, values) -> xr.DataArray:
(
pytest.param(
xr.date_range(start="2024-01-01 01:00", periods=49, freq="1h"),
[0] * 49,
[0.0] * 49,
[0, 0, np.nan],
id="zeros",
),
Expand Down Expand Up @@ -127,7 +125,7 @@ def test_coldata_to_mda8(coldata):
(
(
xr.date_range(start="2024-01-01 01:00", periods=48, freq="1h"),
[0, 1, 2, 3, 4, 5, 6, 7] * 6,
[0.0, 1, 2, 3, 4, 5, 6, 7] * 6,
[np.nan] * 5 + [2.5, 3] + [3.5] * 41,
),
(
Expand Down