Skip to content

BUG: Precision loss when casting 19-digit integer to float #43979

Open
@ch3rn0v

Description

@ch3rn0v

  • 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 master branch of pandas.

Reproducible Example

ls = [
    1234567890123456789,
    np.nan,
    1234567890123337789,
]

pd.Series(ls, dtype=np.float128)

Issue Description

When a series is created from a list that contains np.nan values, its type is float.
And if the list contains 19-digit integers the precision of the last few digits is lost.

A similar issue seems to have been fixed in numpy a couple of years ago: numpy/numpy#9006.

Would you please suggest any workaround until this is resolved? Having a series with integer values and nans would work for me in this particular case. Thank you in advance.

Expected Behavior

The expected behaviour would be to keep the precision exactly.

Installed Versions

INSTALLED VERSIONS

commit : 73c6825
python : 3.8.5.final.0

pandas : 1.3.3
numpy : 1.20.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugConstructorsSeries/DataFrame/Index/pd.array ConstructorsDtype ConversionsUnexpected or buggy dtype conversions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions