Skip to content

Commit 46ba97d

Browse files
committed
BUG: Add failing unit test for GH#34986
1 parent 9c202a1 commit 46ba97d

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

pandas/tests/extension/arrow/arrays.py

Lines changed: 32 additions & 1 deletion
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
@@ -68,7 +69,27 @@ def construct_array_type(cls) -> Type["ArrowStringArray"]:
6869
return ArrowStringArray
6970

7071

71-
class ArrowExtensionArray(OpsMixin, ExtensionArray):
72+
@register_extension_dtype
73+
class ArrowTimestampUSDtype(ExtensionDtype):
74+
75+
type = datetime.datetime
76+
kind = "M"
77+
name = "arrow_timestamp_us"
78+
na_value = pa.NULL
79+
80+
@classmethod
81+
def construct_array_type(cls) -> Type["ArrowTimestampUSArray"]:
82+
"""
83+
Return the array type associated with this dtype.
84+
85+
Returns
86+
-------
87+
type
88+
"""
89+
return ArrowTimestampUSArray
90+
91+
92+
class ArrowExtensionArray(ExtensionArray):
7293
_data: pa.ChunkedArray
7394

7495
@classmethod
@@ -198,3 +219,13 @@ def __init__(self, values):
198219
assert values.type == pa.string()
199220
self._data = values
200221
self._dtype = ArrowStringDtype()
222+
223+
224+
class ArrowTimestampUSArray(ArrowExtensionArray):
225+
def __init__(self, values):
226+
if not isinstance(values, pa.ChunkedArray):
227+
raise ValueError
228+
229+
assert values.type == pa.timestamp("us")
230+
self._data = values
231+
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)