diff --git a/HISTORY.rst b/HISTORY.rst
index ced91a46..a42ac318 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -15,6 +15,7 @@ History
 * Reformatted packaging configuration to pure Py3 wheel that ignore tests and test data
 * Now officially supporting Python3.8
 * Enhancement to precip_accumulation() to allow estimated amounts solid (or liquid) phase precipitation
+* Bugfix for frequency analysis choking on time series with NaNs only.
 
 0.10.x-beta (2019-06-18)
 ------------------------
diff --git a/xclim/generic.py b/xclim/generic.py
index 0fee5a9f..14d6868a 100644
--- a/xclim/generic.py
+++ b/xclim/generic.py
@@ -102,31 +102,42 @@ def fit(da, dist="norm"):
     """
     # Get the distribution
     dc = get_dist(dist)
+    shape_params = [] if dc.shapes is None else dc.shapes.split(",")
+    dist_params = shape_params + ["loc", "scale"]
 
-    # Fit the parameters (lazy computation)
-    data = dask.array.apply_along_axis(
-        dc.fit, da.get_axis_num("time"), da.dropna("time", how="all")
-    )
+    # Fit the parameters.
+    # This would also be the place to impose constraints on the series minimum length if needed.
+    def fitfunc(arr):
+        """Fit distribution parameters."""
+        x = np.ma.masked_invalid(arr).compressed()
 
-    # Count the number of values used for the fit.
-    # n = arr.count(dim='time')
+        # Return NaNs if array is empty.
+        if len(x) <= 1:
+            return [np.nan,] * len(dist_params)
 
-    # Create a view to a DataArray with the desired dimensions to copy them over to the parameter array.
-    mean = da.mean(dim="time", keep_attrs=True)
+        # Fill with NaNs if one of the parameters is NaN
+        params = dc.fit(x)
+        if np.isnan(params).any():
+            params[:] = np.nan
 
-    # Create coordinate for the distribution parameters
-    coords = dict(mean.coords.items())
-    coords["dparams"] = ([] if dc.shapes is None else dc.shapes.split(",")) + [
-        "loc",
-        "scale",
-    ]
+        return params
 
-    # TODO: add time and time_bnds coordinates (Low will work on this)
-    # time.attrs['climatology'] = 'climatology_bounds'
-    # coords['time'] =
-    # coords['climatology_bounds'] =
+    # xarray.apply_ufunc does not yet support multiple outputs with dask parallelism.
+    data = dask.array.apply_along_axis(fitfunc, da.get_axis_num("time"), da)
 
-    out = xr.DataArray(data=data, coords=coords, dims=("dparams",) + mean.dims)
+    # Count the number of values used for the fit.
+    # n = da.notnull().count(dim='time')
+
+    # Coordinates for the distribution parameters
+    coords = dict(da.coords.items())
+    coords.pop("time")
+    coords["dparams"] = dist_params
+
+    # Dimensions for the distribution parameters
+    dims = ["dparams",] + list(da.dims)
+    dims.remove("time")
+
+    out = xr.DataArray(data=data, coords=coords, dims=dims)
     out.attrs = da.attrs
     out.attrs["original_name"] = getattr(da, "standard_name", "")
     out.attrs[
@@ -260,7 +271,7 @@ def frequency_analysis(da, mode, t, dist, window=1, freq=None, **indexer):
     freq = freq or default_freq(**indexer)
 
     # Extract the time series of min or max over the period
-    sel = select_resample_op(da, op=mode, freq=freq, **indexer).dropna(dim="time")
+    sel = select_resample_op(da, op=mode, freq=freq, **indexer)
 
     # Frequency analysis
     return fa(sel, t, dist, mode)

frequency_analysis crashes if there are empty grid cells
* xclim version: 0.11.2
* Python version: 3.6
* Operating System:

### Description
I have a Dataset on a rotated grid (EC-EARTH_HIRHAM5, from CORDEX-NA). I've made a subset for my region, and on the borders of that subset, some grid cells are empty (meaning that all values are NaN).

Following a call to frequency_analysis, the code crashes if I try to save the data to NetCDF, or even with a simple ".values" call. I receive the following error:
ValueError: zero-size array to reduction operation minimum which has no identity


### What I Did
```
import xarray as xr
from xclim import subset
from xclim import generic as xcgen

ds = xr.open_mfdataset("/path/to/rotated/pole/data")  <--- EC-EARTH_HIRHAM5 hourly precipitation for the 1981-2010 period
ds_subset = subset.subset_bbox(ds, lat_bnds=lat_bnds, lon_bnds=lon_bnds)
da_freq = xcgen.frequency_analysis(ds_subset["pr"], mode="max", t=2, dist="genextreme", window=6, freq="YS")
da_freq.isel(return_period=0).values  <-- crashes
```

If I use the following code, everything works fine (except that I get data in locations that should be NaN):
```
import xarray as xr
from xclim import subset
from xclim import generic as xcgen

ds = xr.open_mfdataset("/path/to/rotated/pole/data")
ds_subset = subset.subset_bbox(ds, lat_bnds=lat_bnds, lon_bnds=lon_bnds)
ds_subset["pr"] = ds_subset["pr"].fillna(value=0)  <-- this is the new line
da_freq = xcgen.frequency_analysis(ds_subset["pr"], mode="max", t=2, dist="genextreme", window=6, freq="YS")
da_freq.isel(return_period=0).values  
```

diff --git a/tests/test_generic.py b/tests/test_generic.py
index 38b040b1..67b0a572 100644
--- a/tests/test_generic.py
+++ b/tests/test_generic.py
@@ -42,6 +42,36 @@ class TestFA(object):
         q0 = lognorm.ppf(1 - 1.0 / T, *p0)
         np.testing.assert_array_equal(q[0, 0, 0], q0)
 
+    def test_fit_nan(self):
+        da = self.da.copy()
+        da[0, 0, 0] = np.nan
+        out_nan = generic.fit(da, "lognorm")
+        out_censor = generic.fit(da[1:], "lognorm")
+        np.testing.assert_array_equal(
+            out_nan.values[:, 0, 0], out_censor.values[:, 0, 0]
+        )
+
+    def test_empty(self):
+        da = self.da.copy()
+        da[:, 0, 0] = np.nan
+        out = generic.fit(da, "lognorm").values
+        assert np.isnan(out[:, 0, 0]).all()
+
+
+class TestFrequencyAnalysis:
+    def test_simple(self, ndq_series):
+        q = ndq_series.copy()
+        q[:, 0, 0] = np.nan
+        out = generic.frequency_analysis(
+            q, mode="max", t=2, dist="genextreme", window=6, freq="YS"
+        )
+        assert out.dims == ("return_period", "x", "y")
+        assert out.shape == (1, 2, 3)
+        v = out.values
+        assert v.shape == (1, 2, 3)
+        assert np.isnan(v[:, 0, 0])
+        assert ~np.isnan(v[:, 1, 1])
+
 
 class TestSelectResampleOp:
     def test_month(self, q_series):
diff --git a/tests/test_streamflow.py b/tests/test_streamflow.py
index 41906f4a..b1aa1397 100644
--- a/tests/test_streamflow.py
+++ b/tests/test_streamflow.py
@@ -28,6 +28,14 @@ class Test_FA:
         )
         assert out.shape == (1, 2, 3)
 
+    def test_empty(self, ndq_series):
+        q = ndq_series.copy()
+        q[:, 0, 0] = np.nan
+        out = streamflow.freq_analysis(
+            q, mode="max", t=2, dist="genextreme", window=6, freq="YS"
+        )
+        assert np.isnan(out.values[:, 0, 0]).all()
+
 
 class TestStats:
     def test_simple(self, ndq_series):

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov coveralls
apt-get update apt-get install -y gcc
3.6
requirements_dev.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
bleach==4.1.0
bokeh==2.3.3
boltons==23.1.1
Bottleneck==1.2.1
bump2version==1.0.1
bumpversion==0.6.0
certifi==2021.5.30
cffi==1.15.1
cfgv==3.3.1
cftime==1.0.3.4
charset-normalizer==2.0.12
click==8.0.4
cloudpickle==2.2.1
colorama==0.4.5
contextvars==2.4
coverage==6.2
coveralls==3.3.1
cryptography==40.0.2
dask==2021.3.0
distlib==0.3.9
distributed==2021.3.0
docopt==0.6.2
docutils==0.18.1
filelock==3.4.1
flake8==5.0.4
fsspec==2022.1.0
HeapDict==1.0.1
identify==2.4.4
idna==3.10
immutables==0.19
importlib-metadata==4.2.0
importlib-resources==5.2.3
iniconfig==1.1.1
jeepney==0.7.1
Jinja2==3.0.3
joblib==1.1.1
keyring==23.4.1
locket==1.0.0
MarkupSafe==2.0.1
mccabe==0.7.0
msgpack==1.0.5
netCDF4==1.6.1
nodeenv==1.6.0
numpy==1.19.5
packaging==21.3
pandas==1.1.5
partd==1.2.0
Pillow==8.4.0
Pint==0.17
pkginfo==1.10.0
platformdirs==2.4.0
pluggy==1.0.0
pre-commit==2.17.0
psutil==7.0.0
py==1.11.0
pycodestyle==2.9.1
pycparser==2.21
pyflakes==2.5.0
Pygments==2.14.0
pyparsing==3.1.4
pyproj==2.4.1
pytest==7.0.1
pytest-cov==4.0.0
pytest-runner==5.3.2
python-dateutil==2.9.0.post0
pytz==2025.2
PyYAML==6.0.1
readme-renderer==34.0
requests==2.27.1
requests-toolbelt==1.0.0
rfc3986==1.5.0
scikit-learn==0.24.2
scipy==1.5.4
SecretStorage==3.3.3
six==1.17.0
sortedcontainers==2.4.0
tblib==1.7.0
threadpoolctl==3.1.0
toml==0.10.2
tomli==1.2.3
toolz==0.12.0
tornado==6.1
tox==3.28.0
tqdm==4.64.1
twine==3.8.0
typing_extensions==4.1.1
urllib3==1.26.20
virtualenv==20.16.2
watchdog==2.3.1
webencodings==0.5.1
xarray==0.13.0
-e git+https://github.com/Ouranosinc/xclim.git@608bac4c9976df778fb9fa442ef725c45dde9f36#egg=xclim
zict==2.1.0
zipp==3.6.0

name: xclim
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - bleach==4.1.0
      - bokeh==2.3.3
      - boltons==23.1.1
      - bottleneck==1.2.1
      - bump2version==1.0.1
      - bumpversion==0.6.0
      - cffi==1.15.1
      - cfgv==3.3.1
      - cftime==1.0.3.4
      - charset-normalizer==2.0.12
      - click==8.0.4
      - cloudpickle==2.2.1
      - colorama==0.4.5
      - contextvars==2.4
      - coverage==6.2
      - coveralls==3.3.1
      - cryptography==40.0.2
      - dask==2021.3.0
      - distlib==0.3.9
      - distributed==2021.3.0
      - docopt==0.6.2
      - docutils==0.18.1
      - filelock==3.4.1
      - flake8==5.0.4
      - fsspec==2022.1.0
      - heapdict==1.0.1
      - identify==2.4.4
      - idna==3.10
      - immutables==0.19
      - importlib-metadata==4.2.0
      - importlib-resources==5.2.3
      - iniconfig==1.1.1
      - jeepney==0.7.1
      - jinja2==3.0.3
      - joblib==1.1.1
      - keyring==23.4.1
      - locket==1.0.0
      - markupsafe==2.0.1
      - mccabe==0.7.0
      - msgpack==1.0.5
      - netcdf4==1.6.1
      - nodeenv==1.6.0
      - numpy==1.19.5
      - packaging==21.3
      - pandas==1.1.5
      - partd==1.2.0
      - pillow==8.4.0
      - pint==0.17
      - pkginfo==1.10.0
      - platformdirs==2.4.0
      - pluggy==1.0.0
      - pre-commit==2.17.0
      - psutil==7.0.0
      - py==1.11.0
      - pycodestyle==2.9.1
      - pycparser==2.21
      - pyflakes==2.5.0
      - pygments==2.14.0
      - pyparsing==3.1.4
      - pyproj==2.4.1
      - pytest==7.0.1
      - pytest-cov==4.0.0
      - pytest-runner==5.3.2
      - python-dateutil==2.9.0.post0
      - pytz==2025.2
      - pyyaml==6.0.1
      - readme-renderer==34.0
      - requests==2.27.1
      - requests-toolbelt==1.0.0
      - rfc3986==1.5.0
      - scikit-learn==0.24.2
      - scipy==1.5.4
      - secretstorage==3.3.3
      - six==1.17.0
      - sortedcontainers==2.4.0
      - tblib==1.7.0
      - threadpoolctl==3.1.0
      - toml==0.10.2
      - tomli==1.2.3
      - toolz==0.12.0
      - tornado==6.1
      - tox==3.28.0
      - tqdm==4.64.1
      - twine==3.8.0
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - virtualenv==20.16.2
      - watchdog==2.3.1
      - webencodings==0.5.1
      - xarray==0.13.0
      - zict==2.1.0
      - zipp==3.6.0
prefix: /opt/conda/envs/xclim

tests/test_generic.py::TestFA::test_fit_nan tests/test_generic.py::TestFA::test_empty tests/test_generic.py::TestFrequencyAnalysis::test_simple tests/test_streamflow.py::Test_FA::test_empty
tests/test_generic.py::TestFA::test_fit tests/test_generic.py::TestFA::test_fa tests/test_generic.py::TestSelectResampleOp::test_month tests/test_generic.py::TestSelectResampleOp::test_season_default tests/test_generic.py::TestSelectResampleOp::test_season tests/test_streamflow.py::test_base_flow_index tests/test_streamflow.py::Test_FA::test_simple tests/test_streamflow.py::Test_FA::test_no_indexer tests/test_streamflow.py::Test_FA::test_q27 tests/test_streamflow.py::TestStats::test_simple tests/test_streamflow.py::TestStats::test_missing tests/test_streamflow.py::TestFit::test_simple tests/test_streamflow.py::test_qdoy_max
HISTORY.rst xclim/generic.py
HISTORY.rst xclim/generic.py