@@ -238,7 +238,7 @@ class CombinedDatetimelikeProperties(DatetimeProperties, TimedeltaProperties):
238
238
__doc__ = DatetimeProperties .__doc__
239
239
240
240
241
- def _concat_compat (to_concat , axis = 0 ):
241
+ def _concat_compat (to_concat , axis = 0 , typs = None ):
242
242
"""
243
243
provide concatenation of an datetimelike array of arrays each of which is a
244
244
single M8[ns], datetimet64[ns, tz] or m8[ns] dtype
@@ -272,38 +272,33 @@ def convert_to_pydatetime(x, axis):
272
272
273
273
return x
274
274
275
- typs = get_dtype_kinds (to_concat )
275
+ if typs is None :
276
+ typs = get_dtype_kinds (to_concat )
276
277
277
- # datetimetz
278
- if 'datetimetz' in typs :
279
-
280
- # if to_concat have 'datetime' or 'object'
281
- # then we need to coerce to object
282
- if 'datetime' in typs or 'object' in typs :
283
- to_concat = [convert_to_pydatetime (x , axis ) for x in to_concat ]
284
- return np .concatenate (to_concat , axis = axis )
278
+ # must be single dtype
279
+ if len (typs ) == 1 :
285
280
286
- # we require ALL of the same tz for datetimetz
287
- tzs = set ([getattr (x , 'tz' , None ) for x in to_concat ]) - set ([None ])
288
- if len (tzs ) == 1 :
289
- return DatetimeIndex (np .concatenate ([x .tz_localize (None ).asi8
290
- for x in to_concat ]),
291
- tz = list (tzs )[0 ])
281
+ if 'datetimetz' in typs :
282
+ # datetime with no tz should be stored as "datetime" in typs,
283
+ # thus no need to care
292
284
293
- # single dtype
294
- if len (typs ) == 1 :
285
+ # we require ALL of the same tz for datetimetz
286
+ tzs = set ([x .tz for x in to_concat ])
287
+ if len (tzs ) == 1 :
288
+ return DatetimeIndex (np .concatenate ([x .tz_localize (None ).asi8
289
+ for x in to_concat ]),
290
+ tz = list (tzs )[0 ])
295
291
296
- if not len ( typs - set ([ 'datetime' ])) :
292
+ elif 'datetime' in typs :
297
293
new_values = np .concatenate ([x .view (np .int64 ) for x in to_concat ],
298
294
axis = axis )
299
295
return new_values .view (_NS_DTYPE )
300
296
301
- elif not len ( typs - set ([ 'timedelta' ])) :
297
+ elif 'timedelta' in typs :
302
298
new_values = np .concatenate ([x .view (np .int64 ) for x in to_concat ],
303
299
axis = axis )
304
300
return new_values .view (_TD_DTYPE )
305
301
306
302
# need to coerce to object
307
303
to_concat = [convert_to_pydatetime (x , axis ) for x in to_concat ]
308
-
309
304
return np .concatenate (to_concat , axis = axis )
0 commit comments