Skip to content

TST: fix maybe_promote dt64tz case, 323 xfails #30506

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

Merged
merged 2 commits into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
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/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from pandas._libs import lib, tslib, tslibs
from pandas._libs.tslibs import NaT, OutOfBoundsDatetime, Period, iNaT
from pandas._libs.tslibs.timezones import tz_compare
from pandas.util._validators import validate_bool_kwarg

from .common import (
Expand Down Expand Up @@ -409,6 +410,14 @@ def maybe_promote(dtype, fill_value=np.nan):
elif is_datetime64tz_dtype(dtype):
if isna(fill_value):
fill_value = NaT
elif not isinstance(fill_value, datetime):
dtype = np.dtype(np.object_)
elif fill_value.tzinfo is None:
dtype = np.dtype(np.object_)
elif not tz_compare(fill_value.tzinfo, dtype.tz):
# TODO: sure we want to cast here?
dtype = np.dtype(np.object_)

elif is_extension_array_dtype(dtype) and isna(fill_value):
fill_value = dtype.na_value

Expand Down
8 changes: 0 additions & 8 deletions pandas/tests/dtypes/cast/test_promote.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pytest

from pandas._libs.tslibs import NaT
from pandas.compat import is_platform_windows

from pandas.core.dtypes.cast import maybe_promote
from pandas.core.dtypes.common import (
Expand Down Expand Up @@ -406,7 +405,6 @@ def test_maybe_promote_any_with_datetime64(
_check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar)


@pytest.mark.xfail(reason="Fails to upcast to object")
def test_maybe_promote_datetimetz_with_any_numpy_dtype(
tz_aware_fixture, any_numpy_dtype_reduced
):
Expand All @@ -427,11 +425,6 @@ def test_maybe_promote_datetimetz_with_datetimetz(tz_aware_fixture, tz_aware_fix
dtype = DatetimeTZDtype(tz=tz_aware_fixture)
fill_dtype = DatetimeTZDtype(tz=tz_aware_fixture2)

from dateutil.tz import tzlocal

if is_platform_windows() and tz_aware_fixture2 == tzlocal():
pytest.xfail("Cannot process fill_value with this dtype, see GH 24310")

# create array of given dtype; casts "1" to correct dtype
fill_value = pd.Series([10 ** 9], dtype=fill_dtype)[0]

Expand All @@ -441,7 +434,6 @@ def test_maybe_promote_datetimetz_with_datetimetz(tz_aware_fixture, tz_aware_fix
expected_dtype = dtype
else:
expected_dtype = np.dtype(object)
pytest.xfail("fails to cast to object")

_check_promote(dtype, fill_value, expected_dtype, exp_val_for_scalar)

Expand Down