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

NumPy compatibility in indexing. #395

Open
BalzaniEdoardo opened this issue Jan 15, 2025 · 0 comments
Open

NumPy compatibility in indexing. #395

BalzaniEdoardo opened this issue Jan 15, 2025 · 0 comments

Comments

@BalzaniEdoardo
Copy link
Collaborator

Trying to expand the axis of a TsdFrame results in a pandas error.
Probably what we want is to drop the metadata and expand the dimensions with no errors.

In [5]: nap.TsdFrame(t=np.arange(10),d=np.ones((10, 2)))[:,None]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
...

File ~/.pyenv/versions/3.11.8/envs/pynajax/lib/python3.11/site-packages/pandas/core/indexers/utils.py:341, in disallow_ndim_indexing(result)
    333 """
    334 Helper function to disallow multi-dimensional indexing on 1D Series/Index.
    335 
   (...)
    338 in GH#30588.
    339 """
    340 if np.ndim(result) > 1:
--> 341     raise ValueError(
    342         "Multi-dimensional indexing (e.g. `obj[:, None]`) is no longer "
    343         "supported. Convert to a numpy array before indexing instead."
    344     )

ValueError: Multi-dimensional indexing (e.g. `obj[:, None]`) is no longer supported. Convert to a numpy array before indexing instead.

Also,

nap.TsdTensor(np.arange(10), np.random.randn(10,1,2))[None]

Result in another error:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

In this case the expected behavior would probably be, returning a numpy array with an extra dimension added to the first axis.

as in

nap.TsdTensor(np.arange(10), np.random.randn(10,1,2)).d[None].shape
Out[52]: (1, 10, 1, 2)
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

1 participant