@@ -141,7 +141,7 @@ def wrapper(self, other):
141
141
else :
142
142
if isinstance (other , list ):
143
143
try :
144
- other = type (self )._from_sequence (other )
144
+ other = type (self )._from_sequence_dti (other )
145
145
except ValueError :
146
146
other = np .array (other , dtype = np .object_ )
147
147
elif not isinstance (other , (np .ndarray , ABCIndexClass , ABCSeries ,
@@ -173,7 +173,7 @@ def wrapper(self, other):
173
173
not hasattr (other , 'asi8' )):
174
174
# e.g. other.dtype == 'datetime64[s]'
175
175
# or an object-dtype ndarray
176
- other = type (self )._from_sequence (other )
176
+ other = type (self )._from_sequence_dti (other )
177
177
178
178
result = op (self .view ('i8' ), other .view ('i8' ))
179
179
o_mask = other ._isnan
@@ -327,9 +327,13 @@ def _simple_new(cls, values, freq=None, dtype=None):
327
327
return cls (values , freq = freq , dtype = dtype )
328
328
329
329
@classmethod
330
- def _from_sequence (cls , data , dtype = None , copy = False ,
331
- tz = None , freq = None ,
332
- dayfirst = False , yearfirst = False , ambiguous = 'raise' ):
330
+ def _from_sequence (cls , scalars , dtype = None , copy = False ):
331
+ assert all (isinstance (x , Timestamp ) for x in scalars )
332
+
333
+ @classmethod
334
+ def _from_sequence_dti (cls , data , dtype = None , copy = False ,
335
+ tz = None , freq = None ,
336
+ dayfirst = False , yearfirst = False , ambiguous = 'raise' ):
333
337
334
338
freq , freq_infer = dtl .maybe_infer_freq (freq )
335
339
@@ -735,7 +739,9 @@ def _add_delta(self, delta):
735
739
result : DatetimeArray
736
740
"""
737
741
new_values = super (DatetimeArray , self )._add_delta (delta )
738
- return type (self )._from_sequence (new_values , tz = self .tz , freq = 'infer' )
742
+ result = type (self )(new_values , dtype = self .dtype )
743
+ result ._freq = result .inferred_freq
744
+ return result
739
745
740
746
# -----------------------------------------------------------------
741
747
# Timezone Conversion and Localization Methods
@@ -1074,8 +1080,8 @@ def normalize(self):
1074
1080
new_values [not_null ] = new_values [not_null ] - adjustment
1075
1081
else :
1076
1082
new_values = conversion .normalize_i8_timestamps (self .asi8 , self .tz )
1077
- return type (self )._from_sequence (new_values ,
1078
- freq = 'infer' ) .tz_localize (self .tz )
1083
+ result = type (self )._from_sequence_dti (new_values , freq = 'infer' )
1084
+ resutn result .tz_localize (self .tz )
1079
1085
1080
1086
def to_period (self , freq = None ):
1081
1087
"""
@@ -1664,6 +1670,7 @@ def sequence_to_dt64ns(data, dtype=None, copy=False,
1664
1670
"""
1665
1671
1666
1672
inferred_freq = None
1673
+ inferred_tz = None
1667
1674
1668
1675
dtype = _validate_dt64_dtype (dtype )
1669
1676
@@ -1712,9 +1719,18 @@ def sequence_to_dt64ns(data, dtype=None, copy=False,
1712
1719
tz = maybe_infer_tz (tz , data .tz )
1713
1720
result = data ._data
1714
1721
1715
- elif is_datetime64_dtype (data ):
1722
+ elif inferred_tz is not None :
1723
+ # data returned from objects_to_datetime64ns represenet unix#
1724
+ # timestamps
1725
+ assert data .dtype == 'i8' , data .dtype
1726
+ result = data .view (_NS_DTYPE )
1727
+
1728
+ elif is_datetime64_dtype (data ) or data .dtype == 'i8' :
1716
1729
# tz-naive DatetimeArray or ndarray[datetime64]
1717
1730
data = getattr (data , "_data" , data )
1731
+ if data .dtype == 'i8' :
1732
+ data = data .view (_NS_DTYPE )
1733
+
1718
1734
if data .dtype != _NS_DTYPE :
1719
1735
data = conversion .ensure_datetime64ns (data )
1720
1736
0 commit comments