From d786c7ac2c468b7b429a0066358c9ec67fae760d Mon Sep 17 00:00:00 2001 From: Martin Yeo Date: Wed, 2 Mar 2022 16:50:37 +0000 Subject: [PATCH] NetCDF _lazy_stream_data use np.squeeze to reduce dimensionality. --- lib/iris/fileformats/netcdf.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/iris/fileformats/netcdf.py b/lib/iris/fileformats/netcdf.py index 94395386b7..c28414b2bb 100644 --- a/lib/iris/fileformats/netcdf.py +++ b/lib/iris/fileformats/netcdf.py @@ -2866,11 +2866,12 @@ def _increment_name(self, varname): @staticmethod def _lazy_stream_data(data, fill_value, fill_warn, cf_var): if hasattr(data, "shape") and data.shape == (1,) + cf_var.shape: - # Reduce dimensionality where bounds data is for a scalar point - - # bounds data is 2D but contains just 1 row, which causes - # broadcast ambiguity between the data and its 1D cf_var. # (Don't do this check for string data). - data = np.atleast_1d(data[0]) + # Reduce dimensionality where the data array has an extra dimension + # versus the cf_var - to avoid a broadcasting ambiguity. + # Happens when bounds data is for a scalar point - array is 2D but + # contains just 1 row, so the cf_var is 1D. + data = data.squeeze() if is_lazy_data(data):