modin icon indicating copy to clipboard operation
modin copied to clipboard

Wrong dtypes after `merge` op

Open anmyachev opened this issue 10 months ago • 2 comments

import ray
ray.init()
import modin.pandas as pd

left = pd.DataFrame({"a": [1,2,3], "b": [4,5,6]})
right = pd.DataFrame({"a": [1,2,4], "c": [4,2,6]})
res = left.merge(right, on="a", how="left")

dtypes = res.dtypes
assert dtypes["a"] == "int64"
assert dtypes["b"] == "int64"
assert dtypes["c"] == "float64", f"{str(dtypes['c'])} != float64"  # <- failed

Checked on 3abd961fc746236f75463304803f09241cc3b019.

anmyachev avatar Apr 23 '24 10:04 anmyachev

It seems we can't know new_dtypes for columns other than on in advance. @dchigarev, do you think we should change the logic in _compute_result_metadata to only compute dtypes for on or we should completely remove the logic for new_dtypes computation?https://github.com/modin-project/modin/blob/bbb136d05fa280bdb9c1a0dba56ec74a03019c27/modin/core/storage_formats/pandas/merge.py#L230

YarShev avatar Apr 23 '24 16:04 YarShev

It seems we can't know new_dtypes for columns other than on in advance.

I believe in case of a left-merge we can preserve dtypes for 'on' columns and all the columns from the left frame (since the left frame is never reindexed as far as I understand). We can also keep dtypes for the 'object' columns of the right frame, since in this case the column's dtype won't change even if we add NaNs to it.

For an inner merge, it seems that the current logic of dtypes precomputation works just fine (since we don't add NaNs to columns).

dchigarev avatar Apr 24 '24 07:04 dchigarev