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

indices.generic.doymax | doymin crashes when it encounters an All-Nan slice. #2021

Open
1 of 2 tasks
RondeauG opened this issue Dec 11, 2024 · 0 comments
Open
1 of 2 tasks
Labels
bug Something isn't working

Comments

@RondeauG
Copy link
Contributor

Setup Information

  • Xclim version: v0.53.2

Description

xclim.indices.generic.doymax and xclim.indices.generic.doymin will raise a ValueError when they encounter an All-NaN slice, instead of simply returning a NaN.

Steps To Reproduce

import numpy as np
import xclim as xc
from xclim.testing.helpers import test_timeseries as timeseries

da = timeseries(
    np.repeat(np.nan, 1000),
    variable="tas",
    as_dataset=False
)
da.attrs["units"] = "m3 s-1"

# This crashes
xc.indicators.land.doy_qmax(da)

# This also crashes, and is the line used in `xclim.indices.generic.doymax`
da.argmax(dim="time")

# This also crashes, and is the function used by xarray when calling `da.argmax()`.
np.nanargmax(da.values)

# This returns 0
np.argmax(da.values)

Additional context

While this could seem like a strange thing to want to support, this can hapen fairly often when trying to process multiple stations at the same time (with different start/end dates for their operations). I expect that this would also happen fairly often with freq=MS | QS.

Contribution

  • I would be willing/able to open a Pull Request to address this bug.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@RondeauG RondeauG added the bug Something isn't working label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant