@@ -432,6 +432,12 @@ def _concat_datetime(to_concat, axis=0, typs=None):
432
432
a single array, preserving the combined dtypes
433
433
"""
434
434
435
+ def concatenate (to_concat , axis ):
436
+ # coerce to 2d if needed & concatenate
437
+ if axis == 1 :
438
+ to_concat = [np .atleast_2d (x ) for x in to_concat ]
439
+ return np .concatenate (to_concat , axis = axis )
440
+
435
441
def convert_to_pydatetime (x , axis ):
436
442
# coerce to an object dtype
437
443
@@ -450,8 +456,6 @@ def convert_to_pydatetime(x, axis):
450
456
x = tslib .ints_to_pytimedelta (x .view (np .int64 ).ravel (), box = True )
451
457
x = x .reshape (shape )
452
458
453
- if axis == 1 :
454
- x = np .atleast_2d (x )
455
459
return x
456
460
457
461
if typs is None :
@@ -467,20 +471,15 @@ def convert_to_pydatetime(x, axis):
467
471
if 'datetime' in typs :
468
472
to_concat = [np .array (x , copy = False ).view (np .int64 )
469
473
for x in to_concat ]
470
- if axis == 1 :
471
- to_concat = [np .atleast_2d (x ) for x in to_concat ]
472
-
473
- new_values = np .concatenate (to_concat , axis = axis )
474
- return new_values .view (_NS_DTYPE )
474
+ return concatenate (to_concat , axis = axis ).view (_NS_DTYPE )
475
475
else :
476
476
# when to_concat has different tz, len(typs) > 1.
477
477
# thus no need to care
478
478
return _concat_datetimetz (to_concat )
479
479
480
480
elif 'timedelta' in typs :
481
- new_values = np .concatenate ([x .view (np .int64 ) for x in to_concat ],
482
- axis = axis )
483
- return new_values .view (_TD_DTYPE )
481
+ return concatenate ([x .view (np .int64 ) for x in to_concat ],
482
+ axis = axis ).view (_TD_DTYPE )
484
483
485
484
elif _contains_period :
486
485
# PeriodIndex must be handled by PeriodIndex,
@@ -489,8 +488,8 @@ def convert_to_pydatetime(x, axis):
489
488
raise NotImplementedError
490
489
491
490
# need to coerce to object
492
- to_concat = [convert_to_pydatetime (x , axis ) for x in to_concat ]
493
- return np . concatenate ( to_concat , axis = axis )
491
+ return concatenate ( [convert_to_pydatetime (x , axis ) for x in to_concat ],
492
+ axis = axis )
494
493
495
494
496
495
def _concat_datetimetz (to_concat , name = None ):
0 commit comments