BUG: `hasnans` not accounting for `np.nan` in `FloatingArray`

This issue has been created since 2022-11-21.

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

In [14]: import pandas as pd
In [15]: import numpy as np
In [17]: import pyarrow as pa

In [18]: pa.array([np.nan, 1, 2])
Out[18]: 
<pyarrow.lib.DoubleArray object at 0x7fe90d1f31c0>
[
  nan,
  1,
  2
]
In [22]: x = pa.array([np.nan, 1, 2])

In [24]: pd.Float64Dtype().__from_arrow__(x)
Out[24]: 
<FloatingArray>
[nan, 1.0, 2.0]
Length: 3, dtype: Float64

In [25]: pd.Series(pd.Float64Dtype().__from_arrow__(x))
Out[25]: 
0    NaN
1    1.0
2    2.0
dtype: Float64

In [26]: pd.Series(pd.Float64Dtype().__from_arrow__(x)).hasnans
Out[26]: False

Issue Description

Constructing a Series with Float64Dtype dtype containing np.nan is allowed, but .hasnans returns False instead of True.

Expected Behavior

In [26]: pd.Series(pd.Float64Dtype().__from_arrow__(x)).hasnans
Out[26]: True

Installed Versions

In [27]: pd.show_versions()

INSTALLED VERSIONS

commit : 91111fd
python : 3.9.14.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-76-generic
Version : #86-Ubuntu SMP Fri Jan 17 17:24:28 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.1
numpy : 1.23.5
pytz : 2022.6
dateutil : 2.8.2
setuptools : 65.5.1
pip : 22.3.1
Cython : 0.29.32
pytest : 7.2.0
hypothesis : 6.58.0
sphinx : 5.3.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.6.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli :
fastparquet : None
fsspec : 2022.11.0
gcsfs : None
matplotlib : None
numba : 0.56.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 9.0.0
pyreadstat : None
pyxlsb : None
s3fs : 2022.11.0
scipy : 1.9.3
snappy :
sqlalchemy : 1.4.44
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

mroeschke wrote this answer on 2022-11-21

This behavior might be impacted by discussion in #32265

larsyencken wrote this answer on 2022-11-29

We get the same issue on Python 3.10 and Pandas 1.5.2, where some operations can end you up with a Float64 series that doesn't appear to be expecting np.nan and just doesn't check for it in the expected ways:

In [1]: s = pd.Series([1], dtype='UInt32') / pd.Series([np.nan], dtype='float64')

In [2]: s
Out[2]:
0    NaN
dtype: Float64

In [3]: s.isnull()
Out[3]:
0    False
dtype: bool

In [4]: s.fillna(0)
Out[4]:
0    NaN
dtype: Float64

In [5]: s.hasnans
Out[5]: False
More Details About Repo
Owner Name pandas-dev
Repo Name pandas
Full Name pandas-dev/pandas
Language Python
Created Date 2010-08-24
Updated Date 2022-12-07
Star Count 36164
Watcher Count 1118
Fork Count 15472
Issue Count 3683

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Over resource limits on Streamlit Cloud 0 2022-09-12 2022-09-20
add a "deprecated" property to resources/methods/parameters 13 2014-12-13 2022-11-13
Add support for multiple examples 31 2014-04-07 2022-11-07
Will this tool support testing k8s clusters in the future? 1 2021-11-10 2022-12-05
Colors not written to URL on load 0 2022-03-10 2022-08-27
Add explanation for each tool 0 2022-03-10 2022-07-19
Improve how colors and settings are written to URL 0 2022-03-10 2022-10-05
Not working - Quest 2 1 2021-01-24 2022-05-03
`awatch` on windows can't be killed with Ctrl+C 7 2022-03-24 2022-12-02
fuzzy searching only work partially. 1 2021-10-27 2022-11-12
Win10,QtCreator version:4.9.1,which version of the plugin should I use? 0 2022-04-19 2022-09-24
Block Owasp-Zap and Acunetix scan 3 2021-07-27 2022-09-25
English Keyboard Issues and Feature Requests 1 2021-08-24 2022-08-12
Random "no value provided for variables" even if value was provided 4 2020-09-29 2022-07-20
Where is the link? 1 2021-08-10 2022-01-16
Empty strings in enums results in broken code 1 2022-03-15 2022-11-06
🐛 BUG: @astrojs/vercel completely broken with new RC release 1 2022-07-27 2022-11-09
Reevaluation of next-generation component rewrite 8 2018-05-13 2022-11-15
System by Pass 设置通配不生效 如 172.1.0.0/16 0 2021-12-30 2022-09-24
socks5代理协议转发为http 0 2021-12-29 2022-01-03
VS Extensions 0 2021-10-09 2022-01-04
Hex color code of darker text color? 1 2021-02-26 2022-11-26
🐞 Bug report: The update Button in Pages sometimes does not work 11 2022-08-25 2022-12-02
Alibaba Cloud CLI install script enhancement request 2 2021-03-30 2022-11-01
Is it possible to add htmltoolDependency/styles to waiter? 1 2022-05-04 2022-11-20
vim takes a long time to open the global vimrc 1 2019-01-09 2022-11-29
Supporting Multi question quiz 0 2021-07-13 2022-11-24
Investigate missing warnings and errors for nested configuration 3 2020-07-03 2022-12-01
hagrid launch gets stuck at some point 1 2021-12-01 2022-11-23
hagrid 0.1.9 fails at starting a node on a Raspberry Pi 4 2021-12-07 2022-11-29
Custom labels for sidekiq stats metrics 3 2021-12-02 2022-12-06
Incorrect documentation for BigDecimal#sign 0 2017-10-04 2022-11-25
[Feature Request] Delete all gcode in my USB 3 2022-09-08 2022-11-22
Running on CPU only machine produces error: libcudart.so.10.1: No such file or directory 1 2020-12-31 2022-09-08
driver should be goroutine safe. 1 2021-01-28 2022-12-01
Missing "ACLs" section in ACL policy causes default-allow somehow 3 2021-09-06 2022-12-01
Support forwarding more options to vite in config file 1 2022-05-31 2022-10-15
window not moving when cursor in caret mode reaching the edge of the window. 2 2021-06-12 2022-11-29
Exact Same Location. 19 2017-07-05 2022-11-10
APIView - Reduce number of requests sentd to Devops to get pipeline details 1 2022-11-17 2022-11-24
Way to specify container for this code - DataPath(datastore, path_on_datastore=???) 0 2022-03-24 2022-11-30
APIView - Add option to expand and collapse all documentation 0 2022-11-17 2022-11-24
Bump mkdocs from 1.2.2 to 1.2.3 1 2021-10-18 2022-02-06
precommit failed (help pls) 1 2018-03-28 2022-11-14
Keyword const to replace use of Literal attribute 11 2021-08-15 2022-09-16
Log File collection 2 2017-04-09 2022-01-02
[docs] Enable users in YCQL 0 2022-06-27 2022-09-24
[Bug] 地图实例demo下载本地运行地图不显示,无报错 4 2022-06-17 2022-11-02
Follow up de #80 (propuesta de reonciliación) 9 2015-05-12 2022-12-04
Upload 组件 Upload和Dragger存在循环引用 1 2022-02-10 2022-12-04