11
11
from numpy .lib .format import read_array , write_array
12
12
import numpy as np
13
13
14
- import pandas ._algos as _algos
14
+ import pandas .algos as algos
15
15
import pandas .lib as lib
16
+ import pandas .tslib as tslib
17
+
16
18
from pandas .util import py3compat
17
19
import codecs
18
20
import csv
@@ -84,7 +86,7 @@ def _isnull_ndarraylike(obj):
84
86
result = Series (result , index = obj .index , copy = False )
85
87
elif values .dtype == np .dtype ('M8[ns]' ):
86
88
# this is the NaT pattern
87
- result = values .view ('i8' ) == lib .iNaT
89
+ result = values .view ('i8' ) == tslib .iNaT
88
90
elif issubclass (values .dtype .type , np .timedelta64 ):
89
91
result = - np .isfinite (values .view ('i8' ))
90
92
else :
@@ -168,43 +170,43 @@ def wrapper(arr, indexer, out, fill_value=np.nan):
168
170
169
171
170
172
_take1d_dict = {
171
- 'float64' : _algos .take_1d_float64 ,
172
- 'int32' : _algos .take_1d_int32 ,
173
- 'int64' : _algos .take_1d_int64 ,
174
- 'object' : _algos .take_1d_object ,
175
- 'bool' : _view_wrapper (_algos .take_1d_bool , np .uint8 ),
176
- 'datetime64[ns]' : _view_wrapper (_algos .take_1d_int64 , np .int64 ,
177
- na_override = lib .iNaT ),
173
+ 'float64' : algos .take_1d_float64 ,
174
+ 'int32' : algos .take_1d_int32 ,
175
+ 'int64' : algos .take_1d_int64 ,
176
+ 'object' : algos .take_1d_object ,
177
+ 'bool' : _view_wrapper (algos .take_1d_bool , np .uint8 ),
178
+ 'datetime64[ns]' : _view_wrapper (algos .take_1d_int64 , np .int64 ,
179
+ na_override = tslib .iNaT ),
178
180
}
179
181
180
182
_take2d_axis0_dict = {
181
- 'float64' : _algos .take_2d_axis0_float64 ,
182
- 'int32' : _algos .take_2d_axis0_int32 ,
183
- 'int64' : _algos .take_2d_axis0_int64 ,
184
- 'object' : _algos .take_2d_axis0_object ,
185
- 'bool' : _view_wrapper (_algos .take_2d_axis0_bool , np .uint8 ),
186
- 'datetime64[ns]' : _view_wrapper (_algos .take_2d_axis0_int64 , np .int64 ,
187
- na_override = lib .iNaT ),
183
+ 'float64' : algos .take_2d_axis0_float64 ,
184
+ 'int32' : algos .take_2d_axis0_int32 ,
185
+ 'int64' : algos .take_2d_axis0_int64 ,
186
+ 'object' : algos .take_2d_axis0_object ,
187
+ 'bool' : _view_wrapper (algos .take_2d_axis0_bool , np .uint8 ),
188
+ 'datetime64[ns]' : _view_wrapper (algos .take_2d_axis0_int64 , np .int64 ,
189
+ na_override = tslib .iNaT ),
188
190
}
189
191
190
192
_take2d_axis1_dict = {
191
- 'float64' : _algos .take_2d_axis1_float64 ,
192
- 'int32' : _algos .take_2d_axis1_int32 ,
193
- 'int64' : _algos .take_2d_axis1_int64 ,
194
- 'object' : _algos .take_2d_axis1_object ,
195
- 'bool' : _view_wrapper (_algos .take_2d_axis1_bool , np .uint8 ),
196
- 'datetime64[ns]' : _view_wrapper (_algos .take_2d_axis1_int64 , np .int64 ,
197
- na_override = lib .iNaT ),
193
+ 'float64' : algos .take_2d_axis1_float64 ,
194
+ 'int32' : algos .take_2d_axis1_int32 ,
195
+ 'int64' : algos .take_2d_axis1_int64 ,
196
+ 'object' : algos .take_2d_axis1_object ,
197
+ 'bool' : _view_wrapper (algos .take_2d_axis1_bool , np .uint8 ),
198
+ 'datetime64[ns]' : _view_wrapper (algos .take_2d_axis1_int64 , np .int64 ,
199
+ na_override = tslib .iNaT ),
198
200
}
199
201
200
202
_take2d_multi_dict = {
201
- 'float64' : _algos .take_2d_multi_float64 ,
202
- 'int32' : _algos .take_2d_multi_int32 ,
203
- 'int64' : _algos .take_2d_multi_int64 ,
204
- 'object' : _algos .take_2d_multi_object ,
205
- 'bool' : _view_wrapper (_algos .take_2d_multi_bool , np .uint8 ),
206
- 'datetime64[ns]' : _view_wrapper (_algos .take_2d_multi_int64 , np .int64 ,
207
- na_override = lib .iNaT ),
203
+ 'float64' : algos .take_2d_multi_float64 ,
204
+ 'int32' : algos .take_2d_multi_int32 ,
205
+ 'int64' : algos .take_2d_multi_int64 ,
206
+ 'object' : algos .take_2d_multi_object ,
207
+ 'bool' : _view_wrapper (algos .take_2d_multi_bool , np .uint8 ),
208
+ 'datetime64[ns]' : _view_wrapper (algos .take_2d_multi_int64 , np .int64 ,
209
+ na_override = tslib .iNaT ),
208
210
}
209
211
210
212
@@ -369,9 +371,9 @@ def mask_out_axis(arr, mask, axis, fill_value=np.nan):
369
371
arr [tuple (indexer )] = fill_value
370
372
371
373
_diff_special = {
372
- 'float64' : lib .diff_2d_float64 ,
373
- 'int64' : lib .diff_2d_int64 ,
374
- 'int32' : lib .diff_2d_int32
374
+ 'float64' : algos .diff_2d_float64 ,
375
+ 'int64' : algos .diff_2d_int64 ,
376
+ 'int32' : algos .diff_2d_int32
375
377
}
376
378
377
379
def diff (arr , n , axis = 0 ):
@@ -452,21 +454,21 @@ def wrapper(arr, mask, limit=None):
452
454
f (view , mask , limit = limit )
453
455
return wrapper
454
456
455
- _pad_1d_datetime = _interp_wrapper (_algos .pad_inplace_int64 , np .int64 )
456
- _pad_2d_datetime = _interp_wrapper (_algos .pad_2d_inplace_int64 , np .int64 )
457
- _backfill_1d_datetime = _interp_wrapper (_algos .backfill_inplace_int64 ,
457
+ _pad_1d_datetime = _interp_wrapper (algos .pad_inplace_int64 , np .int64 )
458
+ _pad_2d_datetime = _interp_wrapper (algos .pad_2d_inplace_int64 , np .int64 )
459
+ _backfill_1d_datetime = _interp_wrapper (algos .backfill_inplace_int64 ,
458
460
np .int64 )
459
- _backfill_2d_datetime = _interp_wrapper (_algos .backfill_2d_inplace_int64 ,
461
+ _backfill_2d_datetime = _interp_wrapper (algos .backfill_2d_inplace_int64 ,
460
462
np .int64 )
461
463
462
464
463
465
def pad_1d (values , limit = None , mask = None ):
464
466
if is_float_dtype (values ):
465
- _method = _algos .pad_inplace_float64
467
+ _method = algos .pad_inplace_float64
466
468
elif is_datetime64_dtype (values ):
467
469
_method = _pad_1d_datetime
468
470
elif values .dtype == np .object_ :
469
- _method = _algos .pad_inplace_object
471
+ _method = algos .pad_inplace_object
470
472
else : # pragma: no cover
471
473
raise ValueError ('Invalid dtype for padding' )
472
474
@@ -478,11 +480,11 @@ def pad_1d(values, limit=None, mask=None):
478
480
479
481
def backfill_1d (values , limit = None , mask = None ):
480
482
if is_float_dtype (values ):
481
- _method = _algos .backfill_inplace_float64
483
+ _method = algos .backfill_inplace_float64
482
484
elif is_datetime64_dtype (values ):
483
485
_method = _backfill_1d_datetime
484
486
elif values .dtype == np .object_ :
485
- _method = _algos .backfill_inplace_object
487
+ _method = algos .backfill_inplace_object
486
488
else : # pragma: no cover
487
489
raise ValueError ('Invalid dtype for padding' )
488
490
@@ -495,11 +497,11 @@ def backfill_1d(values, limit=None, mask=None):
495
497
496
498
def pad_2d (values , limit = None , mask = None ):
497
499
if is_float_dtype (values ):
498
- _method = _algos .pad_2d_inplace_float64
500
+ _method = algos .pad_2d_inplace_float64
499
501
elif is_datetime64_dtype (values ):
500
502
_method = _pad_2d_datetime
501
503
elif values .dtype == np .object_ :
502
- _method = _algos .pad_2d_inplace_object
504
+ _method = algos .pad_2d_inplace_object
503
505
else : # pragma: no cover
504
506
raise ValueError ('Invalid dtype for padding' )
505
507
@@ -516,11 +518,11 @@ def pad_2d(values, limit=None, mask=None):
516
518
517
519
def backfill_2d (values , limit = None , mask = None ):
518
520
if is_float_dtype (values ):
519
- _method = _algos .backfill_2d_inplace_float64
521
+ _method = algos .backfill_2d_inplace_float64
520
522
elif is_datetime64_dtype (values ):
521
523
_method = _backfill_2d_datetime
522
524
elif values .dtype == np .object_ :
523
- _method = _algos .backfill_2d_inplace_object
525
+ _method = algos .backfill_2d_inplace_object
524
526
else : # pragma: no cover
525
527
raise ValueError ('Invalid dtype for padding' )
526
528
@@ -903,11 +905,11 @@ def _is_sequence(x):
903
905
except Exception :
904
906
return False
905
907
906
- _ensure_float64 = _algos .ensure_float64
907
- _ensure_int64 = _algos .ensure_int64
908
- _ensure_int32 = _algos .ensure_int32
909
- _ensure_platform_int = _algos .ensure_platform_int
910
- _ensure_object = _algos .ensure_object
908
+ _ensure_float64 = algos .ensure_float64
909
+ _ensure_int64 = algos .ensure_int64
910
+ _ensure_int32 = algos .ensure_int32
911
+ _ensure_platform_int = algos .ensure_platform_int
912
+ _ensure_object = algos .ensure_object
911
913
912
914
913
915
def _astype_nansafe (arr , dtype ):
@@ -916,7 +918,7 @@ def _astype_nansafe(arr, dtype):
916
918
917
919
if issubclass (arr .dtype .type , np .datetime64 ):
918
920
if dtype == object :
919
- return lib .ints_to_pydatetime (arr .view (np .int64 ))
921
+ return tslib .ints_to_pydatetime (arr .view (np .int64 ))
920
922
elif (np .issubdtype (arr .dtype , np .floating ) and
921
923
np .issubdtype (dtype , np .integer )):
922
924
0 commit comments