Skip to content

Commit e793ec6

Browse files
committed
fix: support converting empty time Series to pyarrow Array
1 parent e996883 commit e793ec6

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

tests/unit/test_arrow.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import datetime as dt
16+
17+
import pandas
18+
import pyarrow
19+
import pytest
20+
21+
# To register the types.
22+
import db_dtypes # noqa
23+
24+
25+
@pytest.mark.parametrize(
26+
("series", "expected"),
27+
(
28+
(pandas.Series([], dtype="date"), pyarrow.array([], type=pyarrow.date32())),
29+
(
30+
pandas.Series([None, None, None], dtype="date"),
31+
pyarrow.array([None, None, None], type=pyarrow.date32()),
32+
),
33+
(
34+
pandas.Series(
35+
[dt.date(2021, 9, 27), None, dt.date(2011, 9, 27)], dtype="date"
36+
),
37+
pyarrow.array(
38+
[dt.date(2021, 9, 27), None, dt.date(2011, 9, 27)],
39+
type=pyarrow.date32(),
40+
),
41+
),
42+
(
43+
pandas.Series(
44+
[dt.date(1677, 9, 22), dt.date(1970, 1, 1), dt.date(2262, 4, 11)],
45+
dtype="date",
46+
),
47+
pyarrow.array(
48+
[dt.date(1677, 9, 22), dt.date(1970, 1, 1), dt.date(2262, 4, 11)],
49+
type=pyarrow.date32(),
50+
),
51+
),
52+
(pandas.Series([], dtype="time"), pyarrow.array([], type=pyarrow.time64("ns"))),
53+
(
54+
pandas.Series([None, None, None], dtype="time"),
55+
pyarrow.array([None, None, None], type=pyarrow.time64("ns")),
56+
),
57+
(
58+
pandas.Series(
59+
[dt.time(0, 0, 0, 0), None, dt.time(23, 59, 59, 999_999)], dtype="time"
60+
),
61+
pyarrow.array(
62+
[dt.time(0, 0, 0, 0), None, dt.time(23, 59, 59, 999_999)],
63+
type=pyarrow.time64("ns"),
64+
),
65+
),
66+
),
67+
)
68+
def test_to_arrow(series, expected):
69+
array = pyarrow.array(series)
70+
assert array.equals(expected)

0 commit comments

Comments
 (0)