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
I'm trying to use DataArray.polyfit with a set of weights, but if the data is one-dimensional, I get the following error:
Traceback (most recent call last):
File ".../xarray/.scratch/polyfit-1d-weights.py", line 3, in <module>
xr.DataArray([1, 2, 4], coords=[("x", [1, 2, 3])]).polyfit("x", deg=2, w=[0.1, 0.2, 0.3])
File ".../xarray/xarray/core/dataarray.py", line 5729, in polyfit
return self._to_temp_dataset().polyfit(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../xarray/xarray/core/dataset.py", line 9223, in polyfit
rhs = rhs * w[:, np.newaxis]
~~~~^~~~~~~~~~~~~~~~~~
File ".../xarray/xarray/core/_typed_ops.py", line 934, in __mul__
return self._binary_op(other, operator.mul)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../xarray/xarray/core/variable.py", line 2393, in _binary_op
result = Variable(dims, new_data, attrs=attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../xarray/xarray/core/variable.py", line 424, in __init__
super().__init__(
File ".../xarray/xarray/namedarray/core.py", line 264, in __init__
self._dims = self._parse_dimensions(dims)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../xarray/xarray/namedarray/core.py", line 508, in _parse_dimensions
raise ValueError(
ValueError: dimensions ('x',) must have the same length as the number of data dimensions, ndim=2
What did you expect to happen?
Polyfit should work normally when both the input data and weights are one-dimensional
What happened?
I'm trying to use
DataArray.polyfit
with a set of weights, but if the data is one-dimensional, I get the following error:What did you expect to happen?
Polyfit should work normally when both the input data and weights are one-dimensional
Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
If I artificially add an extra dimension to the data, there is no error. For example, the following works:
Environment
INSTALLED VERSIONS
commit: None
python: 3.12.7 (main, Oct 1 2024, 00:00:00) [GCC 14.2.1 20240912 (Red Hat 14.2.1-3)]
python-bits: 64
OS: Linux
OS-release: 6.11.5-200.fc40.x86_64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: None
libnetcdf: None
xarray: 2024.9.1.dev73+g8f6e45ba
pandas: 2.2.3
numpy: 2.1.2
scipy: None
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
zarr: None
cftime: None
nc_time_axis: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: None
pip: 23.3.2
conda: None
pytest: None
mypy: None
IPython: None
sphinx: None
The text was updated successfully, but these errors were encountered: