Commit 36bc106
fix: add_variables ignoring coords for DataArray bounds (#614)
* Fix add_variables silently ignoring coords for DataArray bounds
When DataArray bounds were passed to add_variables with explicit coords,
the coords parameter was silently ignored because as_dataarray skips
conversion for DataArray inputs. Now validates DataArray bounds against
coords: raises ValueError on mismatched or extra dimensions, and
broadcasts missing dimensions via expand_dims.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Another test
* Add additional test coverage for DataArray bounds validation
Test MultiIndex coords (validation skip), xarray Coordinates object,
dims-only DataArrays, and upper bound mismatch detection.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Add TODO noting as_dataarray fails for scalars with dict coords
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix as_dataarray for scalars with dict coords
Infer dims from dict keys when dims is None and the input is a scalar.
Previously this raised xarray's CoordinateValidationError because
xarray can't broadcast a 0-dim value to coords without explicit dims.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Replace individual tests with parameterized test suite
Consolidate add_variables tests into TestAddVariablesBoundsWithCoords
class with parameterized tests covering all bound types (scalar,
np.number, numpy, pandas, list, DataArray, DataArray-no-coords) x
both coord formats (sequence, dict). Also fixes as_dataarray for
scalars with dict coords by inferring dims from dict keys.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Assert broadcast test checks actual values, not NaN
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Add mixed bound type combination and edge case tests
Test DataArray+numpy, DataArray+scalar, DataArray+DataArray combos for
lower/upper. Also test both bounds covering different dim subsets with
broadcast, and that only the mismatched bound raises ValueError.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Add 0-dim bound types and fix numpy_to_dataarray with dict coords
Add numpy-0d and dataarray-0d to the parameterized bound type tests.
Fix numpy_to_dataarray to infer dims from dict keys for 0-dim arrays,
matching the scalar fix in as_dataarray.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Add tests for inferred coords, multi-dim, string/datetime coords
Cover three gaps: coords inferred from bounds (no coords arg) for
DataArray and pandas, multi-dimensional coord specifications with
both scalar and DataArray bounds, and real-world coordinate types
(string regions, datetime index) including mismatch detection.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Add test for bounds with different dimension order
Verify lower(time, space) and upper(space, time) align correctly
via xarray broadcast.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Reindex DataArray bounds with reordered coordinates
When a DataArray bound has the same coordinate values as coords but in
a different order, reindex to match instead of raising ValueError.
Still raises when the values actually differ (not just reordered).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Fix mypy errors: remove dead code branch, add type annotations
Remove unreachable hasattr(coords, "dims") branch in _coords_to_dict
(xarray Coordinates are Mappings, caught by isinstance check above).
Add Any type annotations to parameterized test arguments.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* Move TestAddVariablesBoundsWithCoords to test_variable.py
Per review feedback, these tests belong in test_variable.py where they
overlap with existing variable tests.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent c6b07e5 commit 36bc106
3 files changed
+383
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
| 194 | + | |
| 195 | + | |
194 | 196 | | |
195 | 197 | | |
196 | 198 | | |
| |||
242 | 244 | | |
243 | 245 | | |
244 | 246 | | |
| 247 | + | |
| 248 | + | |
245 | 249 | | |
246 | 250 | | |
| 251 | + | |
| 252 | + | |
247 | 253 | | |
248 | 254 | | |
249 | 255 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
103 | 170 | | |
104 | 171 | | |
105 | 172 | | |
| |||
611 | 678 | | |
612 | 679 | | |
613 | 680 | | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
614 | 685 | | |
615 | 686 | | |
616 | 687 | | |
| |||
0 commit comments