Skip to content

dtypes convert to object on merge on 1.0.0rc0 #31208

Closed
@mdoom23

Description

@mdoom23

dtypes convert to object on merge

Currently on 1.0.0rc0, when doing a left merge with datetime64[ns] on the right dataframe, if any rows from the left dataframe don't have a match on the right dataframe, then the result dataframe converts datetime to be object. If all items match, then it will remain as a datetime column. This previously maintained dtype in 0.25.3 and 0.24.2.

It seems to no longer maintain the dtype and populate values with NaT.

With 1.0.0rc0, after this I am able to convert to datetime column and it'll properly recognize as a NaT value.

Example with extra value in left dataframe

df1 = pd.DataFrame({'x': {0: 'a', 1: 'b', 2:'c'}, 'y': {0: '1', 1: '2', 2:'4'}})

df2 = pd.DataFrame({'y': {0: '1', 1: '2', 2:'3'}, 'z': {0: '2018-05-01', 1: '2018-05-02', 2:'2018-05-03'}})
df2['z'] = df2['z'].astype('datetime64[ns]')

result = pd.merge(df1, df2, how='left', on='y')

Output

  # 0.24.2
result.dtypes
x            object
y            object
z    datetime64[ns]
dtype: object

  # 0.25.3
result.dtypes
x            object
y            object
z    datetime64[ns]
dtype: object

  # 1.0.0rc0
result.dtypes
x            object
y            object
z            object
dtype: object

Metadata

Metadata

Assignees

No one assigned

    Labels

    DatetimeDatetime data dtypeRegressionFunctionality that used to work in a prior pandas versionReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions