groupby producing incorrect results applying functions to int64 columns due to internal cast to float #6620
Labels
Bug
Dtype Conversions
Unexpected or buggy dtype conversions
Duplicate Report
Duplicate issue or pull request
Groupby
Numeric Operations
Arithmetic, Comparison, and Logical operations
Milestone
dupe of #3707
groupby often casts int64 data to floats before applying functions to the grouped data, and then casts the result back to an int64. This produces incorrect results.
Here is a simple example:
The result is clearly incorrect and should be
z.data and f.data are both numpy.int64, which masks the fact that z.data was converted to a float with a loss of precision during the groupby operation.
Tests of software using groupby on int64 will only show a problem if the tests include integers large enough to cause this loss of precision. Otherwise the tests will pass and the software will just quietly produce incorrect results in production.
The text was updated successfully, but these errors were encountered: