Skip to content

Commit 787d547

Browse files
committed
BUG: Add failing unit test for GH#34986
1 parent 4f7d8bb commit 787d547

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

pandas/tests/extension/arrow/arrays.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
current implementation is not efficient.
88
"""
99
import copy
10+
import datetime
1011
import itertools
1112
import operator
1213
from typing import Type
@@ -67,6 +68,26 @@ def construct_array_type(cls) -> Type["ArrowStringArray"]:
6768
return ArrowStringArray
6869

6970

71+
@register_extension_dtype
72+
class ArrowTimestampUSDtype(ExtensionDtype):
73+
74+
type = datetime.datetime
75+
kind = "M"
76+
name = "arrow_timestamp_us"
77+
na_value = pa.NULL
78+
79+
@classmethod
80+
def construct_array_type(cls) -> Type["ArrowTimestampUSArray"]:
81+
"""
82+
Return the array type associated with this dtype.
83+
84+
Returns
85+
-------
86+
type
87+
"""
88+
return ArrowTimestampUSArray
89+
90+
7091
class ArrowExtensionArray(ExtensionArray):
7192
@classmethod
7293
def from_scalars(cls, values):
@@ -201,3 +222,13 @@ def __init__(self, values):
201222
assert values.type == pa.string()
202223
self._data = values
203224
self._dtype = ArrowStringDtype()
225+
226+
227+
class ArrowTimestampUSArray(ArrowExtensionArray):
228+
def __init__(self, values):
229+
if not isinstance(values, pa.ChunkedArray):
230+
raise ValueError
231+
232+
assert values.type == pa.timestamp("us")
233+
self._data = values
234+
self._dtype = ArrowTimestampUSDtype()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import datetime
2+
3+
import pytest
4+
5+
import pandas as pd
6+
7+
pytest.importorskip("pyarrow", minversion="0.13.0")
8+
9+
from .arrays import ArrowTimestampUSArray # isort:skip
10+
11+
12+
def test_constructor_extensionblock():
13+
# GH 34986
14+
pd.DataFrame(
15+
{
16+
"timestamp": ArrowTimestampUSArray.from_scalars(
17+
[None, datetime.datetime(2010, 9, 8, 7, 6, 5, 4)]
18+
)
19+
}
20+
)

0 commit comments

Comments
 (0)