-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
/
Copy pathtest_timestamp.py
57 lines (40 loc) · 1.3 KB
/
test_timestamp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from __future__ import annotations
import datetime
import pytest
from pandas._typing import type_t
import pandas as pd
from pandas.api.extensions import (
ExtensionDtype,
register_extension_dtype,
)
pytest.importorskip("pyarrow", minversion="1.0.1")
import pyarrow as pa # isort:skip
from pandas.tests.extension.arrow.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_t[ArrowTimestampUSArray]:
"""
Return the array type associated with this dtype.
Returns
-------
type
"""
return ArrowTimestampUSArray
class ArrowTimestampUSArray(ArrowExtensionArray):
def __init__(self, values) -> None:
if not isinstance(values, pa.ChunkedArray):
raise ValueError
assert values.type == pa.timestamp("us")
self._data = values
self._dtype = ArrowTimestampUSDtype() # type: ignore[assignment]
def test_constructor_extensionblock():
# GH 34986
arr = ArrowTimestampUSArray._from_sequence(
[None, datetime.datetime(2010, 9, 8, 7, 6, 5, 4)]
)
pd.DataFrame({"timestamp": arr})