Skip to content

BUG: float64 convert to int64 get confuse result #58929

Closed
@git20190108

Description

@git20190108

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 pandas as pd

#It's different
pd.DataFrame({
    'ori':pd.Series([995279394541916024+i for i in range(128)]).astype('int64'),
    'convert':pd.Series([995279394541916024+i for i in range(128)]).astype('float64').astype('int64'),
             }
            )

Issue Description

Unless the number is very small, converting float to int will result in different values.
And there will be no warning for this change.

import pandas as pd

pd.DataFrame({
    'ori':pd.Series([995279394541916024+i for i in range(128)]).astype('int64'),
    'convert':pd.Series([995279394541916024+i for i in range(128)]).astype('float64').astype('int64'),
             }
            )

image

Expected Behavior

#It's the same
pd.DataFrame({
    'ori':pd.Series([995279394541916+i for i in range(128)]).astype('int64'),
    'convert':pd.Series([995279394541916+i for i in range(128)]).astype('float64').astype('int64'),
             }
            )

image

Installed Versions

python ==3.9
pandas == 2.2.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions