From caf6c6882fa4bc54483b852fce16d6f2f0501540 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Thu, 25 Jun 2020 13:04:29 +0200 Subject: [PATCH 1/2] BUG: Add failing unit test for GH#34986 --- .../tests/extension/arrow/test_timestamp.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 pandas/tests/extension/arrow/test_timestamp.py diff --git a/pandas/tests/extension/arrow/test_timestamp.py b/pandas/tests/extension/arrow/test_timestamp.py new file mode 100644 index 0000000000000..449b50bf88914 --- /dev/null +++ b/pandas/tests/extension/arrow/test_timestamp.py @@ -0,0 +1,57 @@ +import datetime +from typing import Type + +import pytest + +import pandas as pd +from pandas.api.extensions import ExtensionDtype, register_extension_dtype + +pytest.importorskip("pyarrow", minversion="0.13.0") + +import pyarrow as pa # isort:skip + +from .arrays import ArrowExtensionArray # isort:skip + + +@register_extension_dtype +class ArrowTimestampUSDtype(ExtensionDtype): + + type = datetime.datetime + kind = "M" + name = "arrow_timestamp_us" + na_value = pa.NULL + + @classmethod + def construct_array_type(cls) -> Type["ArrowTimestampUSArray"]: + """ + Return the array type associated with this dtype. + + Returns + ------- + type + """ + return ArrowTimestampUSArray + + +class ArrowTimestampUSArray(ArrowExtensionArray): + def __init__(self, values): + if not isinstance(values, pa.ChunkedArray): + raise ValueError + + assert values.type == pa.timestamp("us") + self._data = values + self._dtype = ArrowTimestampUSDtype() + + +@pytest.mark.xfail( + reason="DatetimeTZBlock is created while ExtensionBlock should be, see #34986" +) +def test_constructor_extensionblock(): + # GH 34986 + pd.DataFrame( + { + "timestamp": ArrowTimestampUSArray.from_scalars( + [None, datetime.datetime(2010, 9, 8, 7, 6, 5, 4)] + ) + } + ) From 64dd1d70bd2d7bf4b7e444ef29857afaa224e01e Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Thu, 14 Jan 2021 14:50:21 +0100 Subject: [PATCH 2/2] Remove xfail --- pandas/tests/extension/arrow/test_timestamp.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandas/tests/extension/arrow/test_timestamp.py b/pandas/tests/extension/arrow/test_timestamp.py index 449b50bf88914..29bd3713e9552 100644 --- a/pandas/tests/extension/arrow/test_timestamp.py +++ b/pandas/tests/extension/arrow/test_timestamp.py @@ -43,9 +43,6 @@ def __init__(self, values): self._dtype = ArrowTimestampUSDtype() -@pytest.mark.xfail( - reason="DatetimeTZBlock is created while ExtensionBlock should be, see #34986" -) def test_constructor_extensionblock(): # GH 34986 pd.DataFrame(