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
This bug report was drafted by an AI agent from a reproduced failure. The
reproduction, traceback and cause below are verbatim from the run.
Building a spec model that groups over a string dimension crashes under
pandas 3.0. The grouped operators are affected: sum(by=…), shift(…, by=…), sum_back(…, by=…) and at.
pandas 3.0 defaults string data to the Arrow-backed string dtype
(future.infer_string = True), so a lookup whose values are strings arrives as
an ArrowStringArray. linopy/spec/operators.py::_grouped then calls DataArray.sel(...) on that lookup, and the installed xarray refuses to index
an ArrowStringArray (as_indexable raises TypeError: Invalid array type).
Adding pd.set_option("future.infer_string", False) before the build makes the
same model build and solve. The trigger is the pandas-3.0 string default
producing an ArrowStringArray for the lookup's values.
Suggested fix
In _grouped (linopy/spec/operators.py:263), take the lookup values off the
Arrow-backed dtype before indexing — build keys from a plain object/numpy
view of the values, or avoid .sel here — so string groups index the same way
int and object groups already do.
Full traceback
Traceback (most recent call last):
File "repro.py", line 31, in <module>
linopy.Model.from_spec(spec, data)
File ".../linopy/model.py", line 510, in from_spec
return cls(**model_kwargs).add_spec(spec, sources, retain=retain)
File ".../linopy/model.py", line 494, in add_spec
self._spec = attach(self, spec, sources, retain)
File ".../linopy/spec/accessor.py", line 59, in attach
build(model, bound)
File ".../linopy/spec/builder.py", line 61, in build
_constraints(ctx)
File ".../linopy/spec/builder.py", line 134, in _constraints
lhs, rhs = evaluate(row.lhs, ctx), evaluate(row.rhs, ctx)
File ".../linopy/spec/builder.py", line 225, in evaluate
return operators.shift(
File ".../linopy/spec/operators.py", line 128, in shift
groups = _grouped(over, np.asarray(array.indexes[over]), by)
File ".../linopy/spec/operators.py", line 263, in _grouped
keys = np.asarray(groups.sel({over: labels}).values, dtype=object)
File ".../xarray/core/dataarray.py", line 1729, in sel
ds = self._to_temp_dataset().sel(...)
File ".../xarray/core/dataset.py", line 3086, in sel
result = self.isel(indexers=query_results.dim_indexers, drop=drop)
File ".../xarray/core/dataset.py", line 2939, in isel
var = var.isel(var_indexers)
File ".../xarray/core/variable.py", line 1144, in isel
return self[key]
File ".../xarray/core/variable.py", line 829, in __getitem__
indexable = as_indexable(self._data)
File ".../xarray/core/indexing.py", line 1030, in as_indexable
raise TypeError(f"Invalid array type: {type(array)}")
TypeError: Invalid array type: <class 'pandas.arrays.ArrowStringArray'>
Note
This bug report was drafted by an AI agent from a reproduced failure. The
reproduction, traceback and cause below are verbatim from the run.
Building a spec model that groups over a string dimension crashes under
pandas 3.0. The grouped operators are affected:
sum(by=…),shift(…, by=…),sum_back(…, by=…)andat.pandas 3.0 defaults string data to the Arrow-backed string dtype
(
future.infer_string = True), so a lookup whose values are strings arrives asan
ArrowStringArray.linopy/spec/operators.py::_groupedthen callsDataArray.sel(...)on that lookup, and the installed xarray refuses to indexan
ArrowStringArray(as_indexableraisesTypeError: Invalid array type).Environment
spec-builderbranchMinimal reproduction
Cause, confirmed
Adding
pd.set_option("future.infer_string", False)before the build makes thesame model build and solve. The trigger is the pandas-3.0 string default
producing an
ArrowStringArrayfor the lookup's values.Suggested fix
In
_grouped(linopy/spec/operators.py:263), take the lookup values off theArrow-backed dtype before indexing — build
keysfrom a plain object/numpyview of the values, or avoid
.selhere — so string groups index the same wayint and object groups already do.
Full traceback