Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clip returns DataArray instead of original type #27

Open
mschrimpf opened this issue Oct 10, 2022 · 0 comments
Open

clip returns DataArray instead of original type #27

mschrimpf opened this issue Oct 10, 2022 · 0 comments
Assignees

Comments

@mschrimpf
Copy link
Member

mschrimpf commented Oct 10, 2022

As of xarray 0.18, the clip method uses the apply_ufunc function (pydata/xarray@v0.17.0...v0.18.0#diff-5e1c0e7a002249e30f1e688e4e87af2d67600ce8a240f8b27dccdb28f365c971R381) which in turn uses apply_dataarray_vfunc and ends up returning a DataArray https://github.com/pydata/xarray/blob/v0.18.0/xarray/core/computation.py#L280.

Is there a way to preserve the assembly's original data type? E.g. if we call <BehavioralAssembly>.clip(), we get BehavioralAssembly as output again.

Here's a unit test that fails in 0.18 but works in 0.17:

    def test_clip(self):
        assembly = BehavioralAssembly([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]],
                                      coords={'a': ['a', 'b', 'c', 'd'],
                                              'aa': ('a', ['a', 'a', 'b', 'b']),
                                              'b': ['x', 'y', 'z']},
                                      dims=['a', 'b'])
        clipped = assembly.clip(-5, +5)
        assert type(clipped) == type(assembly)
mschrimpf added a commit to mschrimpf/brain-score that referenced this issue Oct 10, 2022
mschrimpf added a commit to brain-score/vision that referenced this issue Oct 11, 2022
* add `reduce` method to `Score` class for newer xarray

following xarray unpin in brain-score/brainio#25

* cast `condition` coordinate to string

* also cast `condition` to str for precomputed features

* cast clip output to original assembly type

see also brain-score/brainio#27

* keep `importlib-metadata` at version 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants