modin
modin copied to clipboard
Wrong dtypes after `merge` op
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.
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
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).