fix: preserve fallback dimensions in array finalize - #158
Conversation
|
Thank you for this proposed addition. Issue #156 is related to #157, which has been expanded to highlight the underlying problem case that I should have better explained at the time. I will add more description to #156. When an PseudoNetCDFMaskedVariable ufunc is applied, an array is cast as a PseudoNetCDFMaskedVariable. In that case, there are no dimensions or PseudoNetCDF attributes. So, all the defaults get used. Even in that case, In the PseudoNetCDFMaskedVariable ufunc case, the default To make this PR useful, the - ndimensions = getattr(obj, 'dimensions', lambda: self.dtype.char)
+ ndimensions = tuple([f'phony_dim_{i + 1}' for i in range(obj.ndim)])
+ ndimensions = getattr(self, 'dimensions', ndimensions)
+ ndimensions = getattr(obj, 'dimensions', ndimensions)Updated test code should look something like this, and it should fail before the updates and pass after the updates. |
- Generate phony_dim_N tuples matching obj.ndim instead of empty tuple - Check self.dimensions before obj.dimensions for proper precedence - Update test to delete var.dimensions and verify phony fallback - Test now fails before fix and passes after (demonstrates improvement) Addresses maintainer feedback on barronh#158.
|
Updated to address your feedback:
Validation: |
|
Thanks for the update, but I made a mistake in my request. The numbering in netcdf4-c starts at 0. Please just remove the '+ 1' parts and then I will approve this merge. Thanks for your patience. I had put these issues up as notes to myself to address later. I'm grateful that you jumped in. |
…-indexed) Per maintainer feedback in PR barronh#158, netcdf4-c uses 0-indexed phony dimension names. Also updated test expectation to match.
Summary
PseudoNetCDFVariable.__array_finalize__from falling back to the dtype char whenobjhas nodimensionsdimensionstuple already attached to the target viewValidation
pytest src/PseudoNetCDF/test/test_core.py -k "testVar or testFromArray or testArrayFinalizeFallsBackToExistingDimensions"Closes #156