1
+ import datetime
1
2
import decimal
2
3
3
4
import numpy as np
4
5
import pytest
6
+ import pytz
5
7
6
8
from pandas .core .dtypes .dtypes import registry
7
9
@@ -89,11 +91,51 @@ def test_array_copy():
89
91
assert np .shares_memory (a , b ._ndarray ) is True
90
92
91
93
94
+ cet = pytz .timezone ("CET" )
95
+
96
+
92
97
@pytest .mark .parametrize ('data, expected' , [
98
+ # period
93
99
([pd .Period ("2000" , "D" ), pd .Period ("2001" , "D" )],
94
100
period_array (["2000" , "2001" ], freq = "D" )),
101
+
102
+ # interval
95
103
([pd .Interval (0 , 1 ), pd .Interval (1 , 2 )],
96
104
pd .IntervalArray .from_breaks ([0 , 1 , 2 ])),
105
+
106
+ # datetime
107
+ ([pd .Timestamp ('2000' ,), pd .Timestamp ('2001' )],
108
+ pd .arrays .DatetimeArray ._from_sequence (['2000' , '2001' ])),
109
+
110
+ ([datetime .datetime (2000 , 1 , 1 ), datetime .datetime (2001 , 1 , 1 )],
111
+ pd .arrays .DatetimeArray ._from_sequence (['2000' , '2001' ])),
112
+
113
+ (np .array ([1 , 2 ], dtype = 'M8[ns]' ),
114
+ pd .arrays .DatetimeArray (np .array ([1 , 2 ], dtype = 'M8[ns]' ))),
115
+
116
+ (np .array ([1 , 2 ], dtype = 'M8[us]' ),
117
+ pd .arrays .DatetimeArray (np .array ([1000 , 2000 ], dtype = 'M8[ns]' ))),
118
+
119
+ # datetimetz
120
+ ([pd .Timestamp ('2000' , tz = 'CET' ), pd .Timestamp ('2001' , tz = 'CET' )],
121
+ pd .arrays .DatetimeArray ._from_sequence (
122
+ ['2000' , '2001' ], dtype = pd .DatetimeTZDtype (tz = 'CET' ))),
123
+
124
+ ([datetime .datetime (2000 , 1 , 1 , tzinfo = cet ),
125
+ datetime .datetime (2001 , 1 , 1 , tzinfo = cet )],
126
+ pd .arrays .DatetimeArray ._from_sequence (['2000' , '2001' ],
127
+ tz = cet )),
128
+
129
+ # timedelta
130
+ ([pd .Timedelta ('1H' ), pd .Timedelta ('2H' )],
131
+ pd .arrays .TimedeltaArray ._from_sequence (['1H' , '2H' ])),
132
+
133
+ (np .array ([1 , 2 ], dtype = 'm8[ns]' ),
134
+ pd .arrays .TimedeltaArray (np .array ([1 , 2 ], dtype = 'm8[ns]' ))),
135
+
136
+ (np .array ([1 , 2 ], dtype = 'm8[us]' ),
137
+ pd .arrays .TimedeltaArray (np .array ([1000 , 2000 ], dtype = 'm8[ns]' ))),
138
+
97
139
])
98
140
def test_array_inference (data , expected ):
99
141
result = pd .array (data )
@@ -105,6 +147,15 @@ def test_array_inference(data, expected):
105
147
[pd .Period ("2000" , "D" ), pd .Period ("2001" , "A" )],
106
148
# mix of closed
107
149
[pd .Interval (0 , 1 , closed = 'left' ), pd .Interval (1 , 2 , closed = 'right' )],
150
+ # Mix of timezones
151
+ [pd .Timestamp ("2000" , tz = "CET" ), pd .Timestamp ("2000" , tz = "UTC" )],
152
+ # Mix of tz-aware and tz-naive
153
+ [pd .Timestamp ("2000" , tz = "CET" ), pd .Timestamp ("2000" )],
154
+ # GH-24569
155
+ pytest .param (
156
+ np .array ([pd .Timestamp ('2000' ), pd .Timestamp ('2000' , tz = 'CET' )]),
157
+ marks = pytest .mark .xfail (reason = "bug in DTA._from_sequence" )
158
+ ),
108
159
])
109
160
def test_array_inference_fails (data ):
110
161
result = pd .array (data )
0 commit comments