You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What happened:
A linear DataArray.polyfit seems to fail if there are less than 3 non-NaN elements along the fitting dimension.
Traceback
TypeError: only size-1 arrays can be converted to Python scalars
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "polyfit.py", line 6, in <module>
out = arr.polyfit(dim='x', deg=1)
File "/home/stephan/venv/variogram/lib/python3.8/site-packages/xarray/core/dataarray.py", line 3455, in polyfit
return self._to_temp_dataset().polyfit(
File "/home/stephan/venv/variogram/lib/python3.8/site-packages/xarray/core/dataset.py", line 5962, in polyfit
coeffs, residuals = duck_array_ops.least_squares(
File "/home/stephan/venv/variogram/lib/python3.8/site-packages/xarray/core/duck_array_ops.py", line 625, in least_squares
return nputils.least_squares(lhs, rhs, rcond=rcond, skipna=skipna)
File "/home/stephan/venv/variogram/lib/python3.8/site-packages/xarray/core/nputils.py", line 239, in least_squares
out[:, nan_cols] = np.apply_along_axis(
File "<__array_function__ internals>", line 5, in apply_along_axis
File "/home/stephan/venv/variogram/lib/python3.8/site-packages/numpy/lib/shape_base.py", line 379, in apply_along_axis
res = asanyarray(func1d(inarr_view[ind0], *args, **kwargs))
File "/home/stephan/venv/variogram/lib/python3.8/site-packages/xarray/core/nputils.py", line 227, in _nanpolyfit_1d
out[:-1], out[-1], _, _ = np.linalg.lstsq(x[~mask, :], arr[~mask], rcond=rcond)
ValueError: setting an array element with a sequence.
I've played around with the degree a little bit and the error seems to occur as soon as (# of non-NaN values - degree) < 2
What you expected to happen:
The fit to succeed - I think two non-NaN values should be enough for a linear fit. I also noticed that there is no RankWarning: Polyfit may be poorly conditioned if the degree is larger than the number of non-NaN values.
What happened:
A linear
DataArray.polyfit
seems to fail if there are less than 3 non-NaN elements along the fitting dimension.Traceback
I've played around with the degree a little bit and the error seems to occur as soon as
(# of non-NaN values - degree) < 2
What you expected to happen:
The fit to succeed - I think two non-NaN values should be enough for a linear fit. I also noticed that there is no
RankWarning: Polyfit may be poorly conditioned
if the degree is larger than the number of non-NaN values.Minimal Complete Verifiable Example:
Anything else we need to know?:
Environment:
Output of xr.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0]
python-bits: 64
OS: Linux
OS-release: 5.4.0-39-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.4
libnetcdf: 4.6.3
xarray: 0.15.2.dev112+g54b9450b
pandas: 1.0.5
numpy: 1.19.0
scipy: 1.5.0
netCDF4: 1.5.3
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: 2.4.0
cftime: 1.1.3
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: 2.19.0
distributed: 2.19.0
matplotlib: 3.2.2
cartopy: None
seaborn: None
numbagg: None
pint: None
setuptools: 44.0.0
pip: 20.0.2
conda: None
pytest: None
IPython: 7.16.1
sphinx: None
The text was updated successfully, but these errors were encountered: