@@ -119,6 +119,17 @@ def test_take_fill(self):
119
119
arr .take ([0 , 1 ], allow_fill = True ,
120
120
fill_value = pd .Timestamp .now ().time )
121
121
122
+ def test_concat_same_type (self ):
123
+ data = np .arange (10 , dtype = 'i8' )
124
+
125
+ idx = self .index_cls ._simple_new (data , freq = 'D' ).insert (0 , pd .NaT )
126
+ arr = index_to_array (idx )
127
+
128
+ result = arr ._concat_same_type ([arr [:- 1 ], arr [1 :], arr ])
129
+ expected = idx ._concat_same_dtype ([idx [:- 1 ], idx [1 :], idx ], None )
130
+
131
+ tm .assert_index_equal (self .index_cls (result ), expected )
132
+
122
133
123
134
class TestDatetimeArray (SharedTests ):
124
135
index_cls = pd .DatetimeIndex
@@ -200,6 +211,19 @@ def test_int_properties(self, datetime_index, propname):
200
211
201
212
tm .assert_numpy_array_equal (result , expected )
202
213
214
+ def test_concat_same_type_invalid (self , datetime_index ):
215
+ # different timezones
216
+ dti = datetime_index
217
+ arr = DatetimeArrayMixin (dti )
218
+
219
+ if arr .tz is None :
220
+ other = arr .tz_localize ('UTC' )
221
+ else :
222
+ other = arr .tz_localize (None )
223
+
224
+ with pytest .raises (AssertionError ):
225
+ arr ._concat_same_type ([arr , other ])
226
+
203
227
204
228
class TestTimedeltaArray (SharedTests ):
205
229
index_cls = pd .TimedeltaIndex
@@ -239,6 +263,19 @@ def test_astype_object(self):
239
263
assert asobj .dtype == 'O'
240
264
assert list (asobj ) == list (tdi )
241
265
266
+ def test_concat_same_type_invalid (self , timedelta_index ):
267
+ # different freqs
268
+ tdi = timedelta_index
269
+ arr = TimedeltaArrayMixin (tdi )
270
+
271
+ other = pd .timedelta_range ('1D' , periods = 5 , freq = '2D' )
272
+ # FIXME: TimedeltaArray should inherit freq='2D' without specifying it
273
+ other = TimedeltaArrayMixin (other , freq = '2D' )
274
+ assert other .freq != arr .freq
275
+
276
+ with pytest .raises (AssertionError ):
277
+ arr ._concat_same_type ([arr , other ])
278
+
242
279
243
280
class TestPeriodArray (SharedTests ):
244
281
index_cls = pd .PeriodIndex
@@ -315,3 +352,15 @@ def test_int_properties(self, period_index, propname):
315
352
expected = np .array (getattr (pi , propname ))
316
353
317
354
tm .assert_numpy_array_equal (result , expected )
355
+
356
+ def test_concat_same_type_invalid (self , period_index ):
357
+ # different freqs
358
+ pi = period_index
359
+ arr = PeriodArrayMixin (pi )
360
+
361
+ other = pd .period_range ('2016Q3' , periods = 5 , freq = '3Q' )
362
+ other = PeriodArrayMixin (other )
363
+ assert other .freq != arr .freq
364
+
365
+ with pytest .raises (AssertionError ):
366
+ arr ._concat_same_type ([arr , other ])
0 commit comments