-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: DataFrame with scalar tzaware Timestamp #44518
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
Conversation
wdyt?
I have no doubt that this is the correct long term fix, option 2 in #42505 (comment) but not sure if other interactions would expose other latent bugs. This is fine for 1.4 IMO, but would a more narrowly targeted fix for 1.3.5 be safer, option 3 in #42505 (comment) We must have little testing of scalars passed to |
I guess for now put it in the 1.4 file and discuss whether to backport?
Only incorrect behavior AFAICT.
I'm not clear on how we can get more targeted than this. |
this is fine, can you add a whatsnew for 1.3.5 |
This comment has been minimized.
This comment has been minimized.
@meeseeksdev backport 1.3.x |
This comment has been minimized.
This comment has been minimized.
@jbrockmendel if you can push the backport :-<> |
I was thinking special case in So we then have the block... so I was thinking something like... diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py
index 6d5162f3fe..a02e8e085c 100644
--- a/pandas/core/dtypes/cast.py
+++ b/pandas/core/dtypes/cast.py
@@ -1900,6 +1900,8 @@ def construct_1d_arraylike_from_scalar(
"""
+ from pandas.core.arrays import DatetimeArray
+
if dtype is None:
try:
dtype, value = infer_dtype_from_scalar(value, pandas_dtype=True)
@@ -1908,6 +1910,8 @@ def construct_1d_arraylike_from_scalar(
if isinstance(dtype, ExtensionDtype):
cls = dtype.construct_array_type()
+ if issubclass(cls, DatetimeArray) and isinstance(value, Timestamp):
+ value = value.value
subarr = cls._from_sequence([value] * length, dtype=dtype)
else: with an appropriate code comment about the hack. The non-extension array block seems to include some special handling for
yes. any change in behavior from doing the proper fix for 1.3.5 can probably be put under the "bug fix" umbrella, so maybe this is fine. |
…e release note
@simonjayhawkins where does the whatsnew for this go?