-
-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
BUG: DataFrame.select_dtypes(include='number') includes BooleanDtype columns #46870
Comments
take |
Hey @macks22. I was able to recreate this issue on a different OS as well. I am going to start looking into the sourcecode, specifically the df.select_dtypes function to see if I can find what's up. |
@macks22 Here are my examples: In [1] import pandas as pd
df = pd.DataFrame({
'a': [1, 2, 3],
'b': [True, False, True],
'c': [1.0, 2.0,3.0]})
print(df.select_dtypes(include='number').columns)
print('')
print(df.info()) Out [1]
In [2] import pandas as pd
df = pd.DataFrame({
'a': [1, 2, 3],
'b': pd.Series([True, False, True], dtype=pd.BooleanDtype()),
'c': [1.0, 2.0,3.0]})
print(df.select_dtypes(include='number').columns)
print('')
print(df.info()) Out [2]
I forked pandas and created the following branch for my debugging: Courses of action: |
Thanks @macks22 for the report.
in 1.2.5 as EAs were not considered and therefore the
agreed. numpy backed first bad commit: [deaf138] BUG: Allow numeric ExtensionDtypes in DataFrame.select_dtypes (#38246) |
@simonjayhawkins The bug was in the following location: my change is pushed to https://github.com/MichaelRocchio/pandas/tree/issue_46870 It was pretty small: @property
def _is_numeric(self) -> bool:
return True changed to: @property
def _is_numeric(self) -> bool:
return False Additionally I will need help on how to test if my fix didn't cause other issues. |
moving to 1.4.4 |
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
Issue Description
The
DataFrame.select_dtypes
method includes columns withdtype
ofBooleanDtype
wheninclude='number'
is given as a kwarg. This is different than the behavior for columns withdtype
ofbool
and seems like a bug.Expected Behavior
The code above should output:
Index(['a'], dtype='object')
Installed Versions
INSTALLED VERSIONS
commit : 4bfe3d0
python : 3.9.12.final.0
python-bits : 64
OS : Darwin
OS-release : 20.6.0
Version : Darwin Kernel Version 20.6.0: Tue Feb 22 21:10:41 PST 2022; root:xnu-7195.141.26~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.4.2
numpy : 1.21.5
pytz : 2021.3
dateutil : 2.8.2
pip : 21.2.4
setuptools : 59.8.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.2.0
pandas_datareader: None
bs4 : None
bottleneck : 1.3.4
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : None
matplotlib : None
numba : None
numexpr : 2.8.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: