<h3 dir="auto">Describe the issue:</h3>
<p dir="auto">Before version 1.24, <code class="notranslate">numpy.masked_invalid</code> was converting its input to a numpy array, which allowed to pass array-like input.<br>
Changes in  <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1317585663" data-permission-text="Title is private" data-url="https://github.com/numpy/numpy/issues/22046" data-hovercard-type="pull_request" data-hovercard-url="/numpy/numpy/pull/22046/hovercard" href="https://github.com/numpy/numpy/pull/22046">#22046</a> breaks this, which makes for instance some function in matplotlib fails with pandas series (for instance <code class="notranslate">fill_betweenx</code>.</p>
<p dir="auto">I don't know if this is an intended change to only support <code class="notranslate">np.array</code> here, but I just wanted to document this.<br>
I will also report to the <code class="notranslate">matplotlib</code> developpers.</p>
<h3 dir="auto">Reproduce the code example:</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
import pandas as pd

np.ma.masked_invalid(pd.Series([1, 2, 3]))"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>

<span class="pl-s1">np</span>.<span class="pl-s1">ma</span>.<span class="pl-en">masked_invalid</span>(<span class="pl-s1">pd</span>.<span class="pl-v">Series</span>([<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>]))</pre></div>
<h3 dir="auto">Error message:</h3>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 1
----&gt; 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     &quot;&quot;&quot;
   2334     Mask an array where invalid values occur (NaNs or infs).
   2335 
   (...)
   2357 
   2358     &quot;&quot;&quot;
-&gt; 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''"><pre class="notranslate">---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 1
----<span class="pl-k">&gt;</span> 1 np.ma.masked_invalid(pd.Series([1, 2, 3]))

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

TypeError: ufunc <span class="pl-s"><span class="pl-pds">'</span>isfinite<span class="pl-pds">'</span></span> not supported <span class="pl-k">for</span> the input types, and the inputs could not be safely coerced to any supported types according to the casting rule <span class="pl-s"><span class="pl-pds">'</span><span class="pl-pds">'</span></span>safe<span class="pl-s"><span class="pl-pds">'</span><span class="pl-pds">'</span></span></pre></div>
<h3 dir="auto">NumPy/Python version information:</h3>
<p dir="auto">This starts to fail with numpy 1.24. Working with previous version.</p>
<h3 dir="auto">Context for the issue:</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Describe the issue:</h3>
<p dir="auto">Hello, this just popped up <a href="https://github.com/mwaskom/seaborn/actions/runs/3728877621/jobs/6324262230">in my tests</a> with the 1.24.0 release:</p>
<h3 dir="auto">Reproduce the code example:</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np, pandas as pd
np.ma.masked_invalid(pd.Series([1., 2.]))"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>, <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>
<span class="pl-s1">np</span>.<span class="pl-s1">ma</span>.<span class="pl-en">masked_invalid</span>(<span class="pl-s1">pd</span>.<span class="pl-v">Series</span>([<span class="pl-c1">1.</span>, <span class="pl-c1">2.</span>]))</pre></div>
<h3 dir="auto">Error message:</h3>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [35], line 2
      1 import numpy as np, pandas as pd
----&gt; 2 np.ma.masked_invalid(pd.Series([1., 2.]))

File ~/miniconda/envs/py310/lib/python3.10/site-packages/numpy/ma/core.py:2360, in masked_invalid(a, copy)
   2332 def masked_invalid(a, copy=True):
   2333     &quot;&quot;&quot;
   2334     Mask an array where invalid values occur (NaNs or infs).
   2335 
   (...)
   2357 
   2358     &quot;&quot;&quot;
-&gt; 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''"><pre class="notranslate">---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [35], line 2
      1 import numpy as np, pandas as pd
----<span class="pl-k">&gt;</span> 2 np.ma.masked_invalid(pd.Series([1., 2.]))

File <span class="pl-k">~</span>/miniconda/envs/py310/lib/python3.10/site-packages/numpy/ma/core.py:2360, <span class="pl-k">in</span> masked_invalid(a, copy)
   2332 def masked_invalid(a, copy=True):
   2333     <span class="pl-s"><span class="pl-pds">"</span><span class="pl-pds">"</span><span class="pl-pds">"</span></span>
<span class="pl-s">   2334     Mask an array where invalid values occur (NaNs or infs).</span>
<span class="pl-s">   2335 </span>
<span class="pl-s">   (...)</span>
<span class="pl-s">   2357 </span>
<span class="pl-s">   2358     <span class="pl-pds">"</span><span class="pl-pds">"</span><span class="pl-pds">"</span></span>
-<span class="pl-k">&gt;</span> 2360     <span class="pl-k">return</span> masked_where(~(np.isfinite(getdata(a))), a, copy=copy)

TypeError: ufunc <span class="pl-s"><span class="pl-pds">'</span>isfinite<span class="pl-pds">'</span></span> not supported <span class="pl-k">for</span> the input types, and the inputs could not be safely coerced to any supported types according to the casting rule <span class="pl-s"><span class="pl-pds">'</span><span class="pl-pds">'</span></span>safe<span class="pl-s"><span class="pl-pds">'</span><span class="pl-pds">'</span></span></pre></div>
<h3 dir="auto">NumPy/Python version information:</h3>
<p dir="auto">1.24.0 3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:38:29) [Clang 13.0.1 ]</p>
<p dir="auto">Pandas is 1.5.2</p>
<h3 dir="auto">Context for the issue:</h3>
<p dir="auto">The issue seems to be with <code class="notranslate">getdata</code>, which is pulling out the <del>index</del> block manager rather than the values:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="np.ma.getdata(pd.Series([1., 2.]))"><pre class="notranslate"><span class="pl-s1">np</span>.<span class="pl-s1">ma</span>.<span class="pl-en">getdata</span>(<span class="pl-s1">pd</span>.<span class="pl-v">Series</span>([<span class="pl-c1">1.</span>, <span class="pl-c1">2.</span>]))</pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="SingleBlockManager
Items: RangeIndex(start=0, stop=2, step=1)
NumericBlock: 2 dtype: float64"><pre class="notranslate"><code class="notranslate">SingleBlockManager
Items: RangeIndex(start=0, stop=2, step=1)
NumericBlock: 2 dtype: float64
</code></pre></div>
<p dir="auto">Reporting to numpy rather than pandas as the error emerged with the numpy 1.24.0 update; perhaps it's an issue on the pandas side though.</p>