Skip to content

Commit caf6c68

Browse files
committed
BUG: Add failing unit test for GH#34986
1 parent 25110a9 commit caf6c68

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import datetime
2+
from typing import Type
3+
4+
import pytest
5+
6+
import pandas as pd
7+
from pandas.api.extensions import ExtensionDtype, register_extension_dtype
8+
9+
pytest.importorskip("pyarrow", minversion="0.13.0")
10+
11+
import pyarrow as pa # isort:skip
12+
13+
from .arrays import ArrowExtensionArray # isort:skip
14+
15+
16+
@register_extension_dtype
17+
class ArrowTimestampUSDtype(ExtensionDtype):
18+
19+
type = datetime.datetime
20+
kind = "M"
21+
name = "arrow_timestamp_us"
22+
na_value = pa.NULL
23+
24+
@classmethod
25+
def construct_array_type(cls) -> Type["ArrowTimestampUSArray"]:
26+
"""
27+
Return the array type associated with this dtype.
28+
29+
Returns
30+
-------
31+
type
32+
"""
33+
return ArrowTimestampUSArray
34+
35+
36+
class ArrowTimestampUSArray(ArrowExtensionArray):
37+
def __init__(self, values):
38+
if not isinstance(values, pa.ChunkedArray):
39+
raise ValueError
40+
41+
assert values.type == pa.timestamp("us")
42+
self._data = values
43+
self._dtype = ArrowTimestampUSDtype()
44+
45+
46+
@pytest.mark.xfail(
47+
reason="DatetimeTZBlock is created while ExtensionBlock should be, see #34986"
48+
)
49+
def test_constructor_extensionblock():
50+
# GH 34986
51+
pd.DataFrame(
52+
{
53+
"timestamp": ArrowTimestampUSArray.from_scalars(
54+
[None, datetime.datetime(2010, 9, 8, 7, 6, 5, 4)]
55+
)
56+
}
57+
)

0 commit comments

Comments
 (0)