@@ -25,12 +25,6 @@ def _utc():
25
25
26
26
# -------- some conversion wrapper functions
27
27
28
- def _as_i8 (arg ):
29
- if isinstance (arg , np .ndarray ) and arg .dtype == np .datetime64 :
30
- return arg .view ('i8' , type = np .ndarray )
31
- else :
32
- return arg
33
-
34
28
35
29
def _field_accessor (name , field ):
36
30
def f (self ):
@@ -43,19 +37,6 @@ def f(self):
43
37
f .__name__ = name
44
38
return property (f )
45
39
46
- def _wrap_i8_function (f ):
47
- @staticmethod
48
- def wrapper (* args , ** kwargs ):
49
- view_args = [_as_i8 (arg ) for arg in args ]
50
- return f (* view_args , ** kwargs )
51
- return wrapper
52
-
53
- def _wrap_dt_function (f ):
54
- @staticmethod
55
- def wrapper (* args , ** kwargs ):
56
- view_args = [_dt_box_array (_as_i8 (arg )) for arg in args ]
57
- return f (* view_args , ** kwargs )
58
- return wrapper
59
40
60
41
def _join_i8_wrapper (joinf , with_indexers = True ):
61
42
@staticmethod
@@ -72,6 +53,7 @@ def wrapper(left, right):
72
53
return results
73
54
return wrapper
74
55
56
+
75
57
def _dt_index_cmp (opname ):
76
58
"""
77
59
Wrap comparison operations to convert datetime-like to datetime64
@@ -87,32 +69,14 @@ def wrapper(self, other):
87
69
other = _ensure_datetime64 (other )
88
70
result = func (other )
89
71
90
- try :
91
- return result .view (np .ndarray )
92
- except :
93
- return result
72
+ return result .view (np .ndarray )
73
+
94
74
return wrapper
95
75
96
76
def _ensure_datetime64 (other ):
97
77
if isinstance (other , np .datetime64 ):
98
78
return other
99
- elif com .is_integer (other ):
100
- return np .int64 (other ).view ('M8[us]' )
101
- else :
102
- raise TypeError (other )
103
-
104
- def _dt_index_op (opname ):
105
- """
106
- Wrap arithmetic operations to convert timedelta to a timedelta64.
107
- """
108
- def wrapper (self , other ):
109
- if isinstance (other , timedelta ):
110
- func = getattr (self , opname )
111
- return func (np .timedelta64 (other ))
112
- else :
113
- func = getattr (super (DatetimeIndex , self ), opname )
114
- return func (other )
115
- return wrapper
79
+ raise TypeError ('%s type object %s' % (type (other ), str (other )))
116
80
117
81
118
82
class TimeSeriesError (Exception ):
@@ -154,8 +118,7 @@ class DatetimeIndex(Int64Index):
154
118
_left_indexer = _join_i8_wrapper (_algos .left_join_indexer_int64 )
155
119
_left_indexer_unique = _join_i8_wrapper (
156
120
_algos .left_join_indexer_unique_int64 , with_indexers = False )
157
-
158
- _arrmap = _wrap_dt_function (_algos .arrmap_object )
121
+ _arrmap = None
159
122
160
123
__eq__ = _dt_index_cmp ('__eq__' )
161
124
__ne__ = _dt_index_cmp ('__ne__' )
@@ -194,11 +157,6 @@ def __new__(cls, data=None,
194
157
warnings .warn ("parameter 'offset' is deprecated, "
195
158
"please use 'freq' instead" ,
196
159
FutureWarning )
197
- if isinstance (freq , basestring ):
198
- freq = to_offset (freq )
199
- else :
200
- if isinstance (freq , basestring ):
201
- freq = to_offset (freq )
202
160
203
161
offset = freq
204
162
@@ -223,9 +181,6 @@ def __new__(cls, data=None,
223
181
'collection of some kind, %s was passed'
224
182
% repr (data ))
225
183
226
- if isinstance (data , datetime ):
227
- data = [data ]
228
-
229
184
# other iterable of some kind
230
185
if not isinstance (data , (list , tuple )):
231
186
data = list (data )
@@ -244,17 +199,16 @@ def __new__(cls, data=None,
244
199
elif issubclass (data .dtype .type , np .datetime64 ):
245
200
if isinstance (data , DatetimeIndex ):
246
201
subarr = data .values
247
- offset = data .offset
248
- verify_integrity = False
202
+ if offset is None :
203
+ offset = data .offset
204
+ verify_integrity = False
249
205
else :
250
206
if data .dtype != _NS_DTYPE :
251
207
subarr = lib .cast_to_nanoseconds (data )
252
208
else :
253
209
subarr = data
254
210
elif data .dtype == _INT64_DTYPE :
255
- subarr = data .view (_NS_DTYPE )
256
- elif issubclass (data .dtype .type , np .integer ):
257
- subarr = np .array (data , dtype = _NS_DTYPE , copy = copy )
211
+ subarr = np .asarray (data , dtype = _NS_DTYPE )
258
212
else :
259
213
subarr = tools .to_datetime (data )
260
214
if not np .issubdtype (subarr .dtype , np .datetime64 ):
@@ -295,10 +249,6 @@ def _generate(cls, start, end, periods, name, offset,
295
249
296
250
if start is not None :
297
251
start = Timestamp (start )
298
- if not isinstance (start , Timestamp ):
299
- raise ValueError ('Failed to convert %s to timestamp'
300
- % start )
301
-
302
252
if normalize :
303
253
start = normalize_date (start )
304
254
_normalized = True
@@ -307,9 +257,6 @@ def _generate(cls, start, end, periods, name, offset,
307
257
308
258
if end is not None :
309
259
end = Timestamp (end )
310
- if not isinstance (end , Timestamp ):
311
- raise ValueError ('Failed to convert %s to timestamp'
312
- % end )
313
260
314
261
if normalize :
315
262
end = normalize_date (end )
@@ -319,6 +266,9 @@ def _generate(cls, start, end, periods, name, offset,
319
266
320
267
start , end , tz = tools ._figure_out_timezone (start , end , tz )
321
268
269
+ if com ._count_not_none (start , end , periods ) < 2 :
270
+ raise ValueError ('Must specify two of start, end, or periods' )
271
+
322
272
if (offset ._should_cache () and
323
273
not (offset ._normalize_cache and not _normalized ) and
324
274
_naive_in_cache_range (start , end )):
@@ -329,7 +279,7 @@ def _generate(cls, start, end, periods, name, offset,
329
279
330
280
if tz is not None :
331
281
# Convert local to UTC
332
- ints = index .view ('i8' )
282
+ ints = index .view ('i8' , type = np . ndarray )
333
283
index = lib .tz_localize_to_utc (ints , tz )
334
284
index = index .view (_NS_DTYPE )
335
285
@@ -384,11 +334,6 @@ def _cached_range(cls, start=None, end=None, periods=None, offset=None,
384
334
cachedRange = drc [offset ]
385
335
386
336
if start is None :
387
- if end is None :
388
- raise Exception ('Must provide start or end date!' )
389
- if periods is None :
390
- raise Exception ('Must provide number of periods!' )
391
-
392
337
assert (isinstance (end , Timestamp ))
393
338
394
339
end = offset .rollback (end )
@@ -400,9 +345,6 @@ def _cached_range(cls, start=None, end=None, periods=None, offset=None,
400
345
start = offset .rollforward (start )
401
346
402
347
startLoc = cachedRange .get_loc (start )
403
- if periods is None :
404
- raise Exception ('Must provide number of periods!' )
405
-
406
348
endLoc = startLoc + periods
407
349
else :
408
350
if not offset .onOffset (start ):
@@ -1050,7 +992,7 @@ def map(self, f):
1050
992
try :
1051
993
return f (self )
1052
994
except :
1053
- return Index . map (self , f )
995
+ return _algos . arrmap_object (self . asobject , f )
1054
996
1055
997
# alias to offset
1056
998
@property
@@ -1330,9 +1272,6 @@ def indexer_between_time(self, start_time, end_time, include_start=True,
1330
1272
return mask .nonzero ()[0 ]
1331
1273
1332
1274
def _generate_regular_range (start , end , periods , offset ):
1333
- if com ._count_not_none (start , end , periods ) < 2 :
1334
- raise ValueError ('Must specify two of start, end, or periods' )
1335
-
1336
1275
if isinstance (offset , Tick ):
1337
1276
stride = offset .nanos
1338
1277
if periods is None :
@@ -1461,9 +1400,9 @@ def parser(x):
1461
1400
result = parse_time_string (x , offset )
1462
1401
return result [0 ]
1463
1402
1464
- p_ufunc = np .frompyfunc ( parser , 1 , 1 )
1465
- data = p_ufunc (arr )
1466
- return np . array (data , dtype = _NS_DTYPE )
1403
+ arr = np .asarray ( arr , dtype = object )
1404
+ data = _algos . arrmap_object (arr , parser )
1405
+ return tools . to_datetime (data )
1467
1406
1468
1407
1469
1408
_CACHE_START = Timestamp (datetime (1950 , 1 , 1 ))
@@ -1481,9 +1420,6 @@ def _naive_in_cache_range(start, end):
1481
1420
def _in_range (start , end , rng_start , rng_end ):
1482
1421
return start > rng_start and end < rng_end
1483
1422
1484
- def _time_to_nanosecond (time ):
1485
- return _time_to_micros (time ) * 1000
1486
-
1487
1423
def _time_to_micros (time ):
1488
1424
seconds = time .hour * 60 * 60 + 60 * time .minute + time .second
1489
1425
return 1000000 * seconds + time .microsecond
0 commit comments