Skip to content

Squeeze 1,1 patch fails #623

@d-chambers

Description

@d-chambers

Description

Using patch.squeeze() raises an exception when the patch has a shape of (1, 1).

Example

  import dascore as dc                                                                                                                                                                                                   
                                                                                                                                                                                                                           
  patch = dc.get_example_patch()          
                                                                                                                                                                                 
  # Aggregate over all dims with dim_reduce='empty' → (1, 1) shaped patch                                                                                                                                                  
  agg = patch.aggregate(dim=None, method="mean", dim_reduce="empty")                                                                                                                                                       
                                                                                                                                                                                                                           
  agg.squeeze()  # AssertionError: dim mismatch on coords and attrs                                                                                                                                                        
                                                                                                                                                                                                                                                                                                              

The bug: aggregate(dim=None, dim_reduce='empty') produces a (1, 1) patch where both dims have length 1. squeeze() then drops both dims from the CoordManager, making coords.dims = (), but attrs.dim_tuple still returns
('distance', 'time') — the attrs are not updated to reflect the dropped dims.

Expected behavior

In the numpy sense, squeezing a (1,1) array drops both axes → scalar. So the patch should become 0-D: dims = (), data.shape = ().

in xarray, dataarray.data becomes a 0-D numpy array — still an ndarray, shape (), ndim 0. It's a scalar value but not a Python scalar; dascore should work in the same way.

Versions

  • OS [e.g. Ubuntu 20.04]:
  • DASCore Version [e.g. 0.0.5]: 0.1.14
  • Python Version [e.g. 3.10]:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions