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

BUG: Creation of UInt64 column with 18446744073709551615 throws RuntimeWarning #60050

Open
2 of 3 tasks
Tracked by #60214
Tishj opened this issue Oct 15, 2024 · 3 comments
Open
2 of 3 tasks
Tracked by #60214
Assignees
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors ExtensionArray Extending pandas with custom dtypes or arrays.

Comments

@Tishj
Copy link

Tishj commented Oct 15, 2024

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

import numpy.ma
import pandas

print(pandas.__version__)

data = {
	'a': numpy.ma.masked_array(
		mask=[
			True,
			True,
			False
		],
		data=[
			0, 0, 18446744073709551615
		],
		dtype='uint64'
	)
}

data['a'] = pandas.Series(data['a'], dtype='UInt64')

df = pandas.DataFrame.from_dict(data)
print(df['a'].dtype)
print(df)
2.2.3
/Users/thijs/.pyenv/versions/3.11.0/lib/python3.11/site-packages/pandas/core/arrays/integer.py:55: RuntimeWarning: invalid value encountered in cast
  casted = values.astype(dtype, copy=copy)
UInt64
                      a
0                  <NA>
1                  <NA>
2  18446744073709551615

Issue Description

Creating a nullable uint64 column throws errors

Expected Behavior

I would expect this to work without throwing an error, I don't get why the data is interpreted as a float64 when uint64 is explicitly set as the dtype on the masked array

Installed Versions

INSTALLED VERSIONS
------------------
commit                : 0691c5cf90477d3503834d983f69350f250a6ff7
python                : 3.11.0
python-bits           : 64
OS                    : Darwin
OS-release            : 23.1.0
Version               : Darwin Kernel Version 23.1.0: Mon Oct  9 21:28:45 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6020
machine               : arm64
processor             : arm
byteorder             : little
LC_ALL                : None
LANG                  : en_US.UTF-8
LOCALE                : en_US.UTF-8

pandas                : 2.2.3
numpy                 : 1.26.4
pytz                  : 2024.1
dateutil              : 2.8.2
pip                   : 24.0
Cython                : 3.0.11
sphinx                : None
IPython               : 8.22.0
adbc-driver-postgresql: None
adbc-driver-sqlite    : None
bs4                   : 4.12.3
blosc                 : None
bottleneck            : None
dataframe-api-compat  : None
fastparquet           : None
fsspec                : 2024.2.0
html5lib              : None
hypothesis            : None
gcsfs                 : None
jinja2                : 3.1.3
lxml.etree            : None
matplotlib            : None
numba                 : None
numexpr               : None
odfpy                 : None
openpyxl              : None
pandas_gbq            : None
psycopg2              : 2.9.9
pymysql               : None
pyarrow               : 17.0.0
pyreadstat            : None
pytest                : 8.0.0
python-calamine       : None
pyxlsb                : None
s3fs                  : None
scipy                 : None
sqlalchemy            : 2.0.35
tables                : None
tabulate              : None
xarray                : None
xlrd                  : None
xlsxwriter            : None
zstandard             : None
tzdata                : 2023.4
qtpy                  : None
pyqt5                 : None
@Tishj Tishj added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 15, 2024
@rhshadrach
Copy link
Member

Thanks for the report. In the Series constructor, we call pandas.core.construction.sanitize_masked_array which coerces the data to float because there are masked values. I'm guessing if we passed the requested dtype and it's a masked EA, we could avoid this.

Further investigations and PRs are welcome!

@rhshadrach rhshadrach added ExtensionArray Extending pandas with custom dtypes or arrays. Constructors Series/DataFrame/Index/pd.array Constructors and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 26, 2024
@lfffkh
Copy link
Contributor

lfffkh commented Nov 6, 2024

take

@lfffkh
Copy link
Contributor

lfffkh commented Nov 23, 2024

Hello everyone, I am a bit confused about how to solve this issue now. In addition to my attempts in PR, I have tried many other methods, but the results have not been very good, so I am currently a bit confused and don't know how to solve this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

No branches or pull requests

3 participants