issues: 648981227
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
648981227 | MDU6SXNzdWU2NDg5ODEyMjc= | 4190 | Polyfit fails with few non-NaN values | 1991007 | closed | 0 | 1 | 2020-07-01T13:26:53Z | 2020-08-20T08:34:45Z | 2020-08-20T08:34:45Z | NONE | What happened:
A linear 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 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 Minimal Complete Verifiable Example: ```python import xarray as xr import numpy as np arr = xr.DataArray([np.nan, 1, 2], dims='x', coords={'x': [0, 1, 2]}) arr.polyfit(dim='x', deg=1) ``` Anything else we need to know?: Environment: Output of <tt>xr.show_versions()</tt>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 |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/4190/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |