Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: masked_invalid does not accept pandas.Series #22829

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

Closed
tomMoral opened this issue Dec 19, 2022 · 1 comment
Closed

BUG: masked_invalid does not accept pandas.Series #22829

tomMoral opened this issue Dec 19, 2022 · 1 comment
Labels

Comments

@tomMoral
Copy link

Describe the issue:

Before version 1.24, numpy.masked_invalid was converting its input to a numpy array, which allowed to pass array-like input.
Changes in #22046 breaks this, which makes for instance some function in matplotlib fails with pandas series (for instance fill_betweenx.

I don't know if this is an intended change to only support np.array here, but I just wanted to document this.
I will also report to the matplotlib developpers.

Reproduce the code example:

import numpy as np
import pandas as pd

np.ma.masked_invalid(pd.Series([1, 2, 3]))

Error message:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 np.ma.masked_invalid(pd.Series([1, 2, 3]))

File ~/.local/miniconda/envs/test_benchopt/lib/python3.11/site-packages/numpy/ma/core.py:2360, in masked_invalid(a, copy)
   2332 def masked_invalid(a, copy=True):
   2333     """
   2334     Mask an array where invalid values occur (NaNs or infs).
   2335 
   (...)
   2357 
   2358     """
-> 2360     return masked_where(~(np.isfinite(getdata(a))), a, copy=copy)

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

NumPy/Python version information:

This starts to fail with numpy 1.24. Working with previous version.

Context for the issue:

No response

@tomMoral
Copy link
Author

tomMoral commented Dec 19, 2022

Closing as this is a duplicate of #22826

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant