Skip to content

BUG: Fix Dataframe handling of scalar Timestamp #61444 #61450

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
)
from pandas._libs.hashtable import duplicated
from pandas._libs.lib import is_range_indexer
from pandas._libs.tslibs.timestamps import Timestamp
from pandas.compat import PYPY
from pandas.compat._constants import REF_COUNT
from pandas.compat._optional import import_optional_dependency
Expand Down Expand Up @@ -4180,6 +4181,14 @@ def __setitem__(self, key, value) -> None:
):
# Column to set is duplicated
self._setitem_array([key], value)
elif (
# GH#61444
isinstance(key, Hashable)
and key in self.columns
and is_scalar(value)
and isinstance(value, (Timestamp, np.datetime64))
):
self._set_item(key, [value] * len(self))
else:
# set column
self._set_item(key, value)
Expand Down
Loading