Skip to content

BUG: Did not expect new dtype datetime64[ns] to equal self.dtype datetime64[ns] #56502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 3 tasks
StefanFrey opened this issue Dec 14, 2023 · 3 comments
Closed
2 of 3 tasks
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Needs Info Clarification about behavior needed to assess issue

Comments

@StefanFrey
Copy link

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

change_date["latest_change_at"].fillna(np.datetime64('2001-01-01T00:00:00'), inplace=True)


AssertionError: Did not expect new dtype datetime64[ns] to equal self.dtype datetime64[ns]. Please report a bug at https://github.com/pandas-dev/pandas/issues.

Issue Description

Original code was:
change_date["latest_change_at"].fillna("2001-01-01T00:00:00Z", inplace=True)
This is my error:
Value '2001-01-01T00:00:00Z' has dtype incompatible with datetime64[ns], please explicitly cast to a compatible dtype first.

So I tried to change the values for the fillna to datetime64[ns] by running this:
change_date["latest_change_at"].fillna(np.datetime64('2001-01-01T00:00:00'), inplace=True)

Expected Behavior

This should cast.

Installed Versions

Pandas 2.1.4

@StefanFrey StefanFrey added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 14, 2023
@phofl
Copy link
Member

phofl commented Dec 14, 2023

Hi, thanks for your report. Can you give us a full reproducer that includes the construction of change_date?

@lithomas1 lithomas1 added Dtype Conversions Unexpected or buggy dtype conversions Needs Info Clarification about behavior needed to assess issue and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 22, 2024
@mroeschke
Copy link
Member

Closing as this issue needs more information to reproduce

@thecurve8
Copy link

thecurve8 commented Mar 31, 2025

import pandas as pd

df = pd.DataFrame({
'datetime' : pd.date_range('1/1/2011', period=3, freq='H'),
'value' : [1,2,3]
})

df.iloc[0,0] = None
df.fillna(pd.Timestamp('0001-01-01'), inplace=True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions Needs Info Clarification about behavior needed to assess issue
Projects
None yet
Development

No branches or pull requests

5 participants