12
12
import pandas .index as _index
13
13
from pandas .util .decorators import Appender
14
14
import pandas .core .common as com
15
- import pandas .core .array as pa
16
15
import pandas .computation .expressions as expressions
17
16
from pandas .core .common import (bind_method , is_list_like , notnull , isnull ,
18
17
_values_from_object , _maybe_match_name )
@@ -332,7 +331,7 @@ def _convert_to_array(self, values, name=None, other=None):
332
331
# a datelike
333
332
elif isinstance (values , pd .DatetimeIndex ):
334
333
values = values .to_series ()
335
- elif not (isinstance (values , (pa . Array , pd .Series )) and
334
+ elif not (isinstance (values , (np . ndarray , pd .Series )) and
336
335
com .is_datetime64_dtype (values )):
337
336
values = tslib .array_to_datetime (values )
338
337
elif inferred_type in ('timedelta' , 'timedelta64' ):
@@ -349,7 +348,7 @@ def _convert_to_array(self, values, name=None, other=None):
349
348
"operation [{0}]" .format (name ))
350
349
elif isinstance (values [0 ], pd .DateOffset ):
351
350
# handle DateOffsets
352
- os = pa .array ([getattr (v , 'delta' , None ) for v in values ])
351
+ os = np .array ([getattr (v , 'delta' , None ) for v in values ])
353
352
mask = isnull (os )
354
353
if mask .any ():
355
354
raise TypeError ("cannot use a non-absolute DateOffset in "
@@ -366,10 +365,10 @@ def _convert_to_array(self, values, name=None, other=None):
366
365
else :
367
366
raise TypeError (
368
367
'incompatible type [{0}] for a datetime/timedelta '
369
- 'operation' .format (pa .array (values ).dtype ))
368
+ 'operation' .format (np .array (values ).dtype ))
370
369
else :
371
370
raise TypeError ("incompatible type [{0}] for a datetime/timedelta"
372
- " operation" .format (pa .array (values ).dtype ))
371
+ " operation" .format (np .array (values ).dtype ))
373
372
374
373
return values
375
374
@@ -408,7 +407,7 @@ def _convert_for_datetime(self, lvalues, rvalues):
408
407
if mask is not None :
409
408
if mask .any ():
410
409
def f (x ):
411
- x = pa .array (x , dtype = self .dtype )
410
+ x = np .array (x , dtype = self .dtype )
412
411
np .putmask (x , mask , self .fill_value )
413
412
return x
414
413
self .wrap_results = f
@@ -449,19 +448,19 @@ def na_op(x, y):
449
448
result = expressions .evaluate (op , str_rep , x , y ,
450
449
raise_on_error = True , ** eval_kwargs )
451
450
except TypeError :
452
- if isinstance (y , (pa . Array , pd .Series , pd .Index )):
451
+ if isinstance (y , (np . ndarray , pd .Series , pd .Index )):
453
452
dtype = np .find_common_type ([x .dtype , y .dtype ], [])
454
453
result = np .empty (x .size , dtype = dtype )
455
454
mask = notnull (x ) & notnull (y )
456
455
result [mask ] = op (x [mask ], _values_from_object (y [mask ]))
457
- elif isinstance (x , pa . Array ):
458
- result = pa .empty (len (x ), dtype = x .dtype )
456
+ elif isinstance (x , np . ndarray ):
457
+ result = np .empty (len (x ), dtype = x .dtype )
459
458
mask = notnull (x )
460
459
result [mask ] = op (x [mask ], y )
461
460
else :
462
461
raise TypeError ("{typ} cannot perform the operation {op}" .format (typ = type (x ).__name__ ,op = str_rep ))
463
462
464
- result , changed = com ._maybe_upcast_putmask (result , ~ mask , pa . NA )
463
+ result , changed = com ._maybe_upcast_putmask (result , ~ mask , np . nan )
465
464
466
465
result = com ._fill_zeros (result , x , y , name , fill_zeros )
467
466
return result
@@ -531,7 +530,7 @@ def na_op(x, y):
531
530
if isinstance (y , list ):
532
531
y = lib .list_to_object_array (y )
533
532
534
- if isinstance (y , (pa . Array , pd .Series )):
533
+ if isinstance (y , (np . ndarray , pd .Series )):
535
534
if y .dtype != np .object_ :
536
535
result = lib .vec_compare (x , y .astype (np .object_ ), op )
537
536
else :
@@ -558,7 +557,7 @@ def wrapper(self, other):
558
557
index = self .index , name = name )
559
558
elif isinstance (other , pd .DataFrame ): # pragma: no cover
560
559
return NotImplemented
561
- elif isinstance (other , (pa . Array , pd .Index )):
560
+ elif isinstance (other , (np . ndarray , pd .Index )):
562
561
if len (self ) != len (other ):
563
562
raise ValueError ('Lengths must match to compare' )
564
563
return self ._constructor (na_op (self .values , np .asarray (other )),
@@ -610,7 +609,7 @@ def na_op(x, y):
610
609
if isinstance (y , list ):
611
610
y = lib .list_to_object_array (y )
612
611
613
- if isinstance (y , (pa . Array , pd .Series )):
612
+ if isinstance (y , (np . ndarray , pd .Series )):
614
613
if (x .dtype == np .bool_ and
615
614
y .dtype == np .bool_ ): # pragma: no cover
616
615
result = op (x , y ) # when would this be hit?
@@ -688,7 +687,7 @@ def flex_wrapper(self, other, level=None, fill_value=None, axis=0):
688
687
self ._get_axis_number (axis )
689
688
if isinstance (other , pd .Series ):
690
689
return self ._binop (other , op , level = level , fill_value = fill_value )
691
- elif isinstance (other , (pa . Array , pd .Series , list , tuple )):
690
+ elif isinstance (other , (np . ndarray , pd .Series , list , tuple )):
692
691
if len (other ) != len (self ):
693
692
raise ValueError ('Lengths must be equal' )
694
693
return self ._binop (self ._constructor (other , self .index ), op ,
@@ -925,10 +924,10 @@ def na_op(x, y):
925
924
except TypeError :
926
925
927
926
# TODO: might need to find_common_type here?
928
- result = pa .empty (len (x ), dtype = x .dtype )
927
+ result = np .empty (len (x ), dtype = x .dtype )
929
928
mask = notnull (x )
930
929
result [mask ] = op (x [mask ], y )
931
- result , changed = com ._maybe_upcast_putmask (result , ~ mask , pa . NA )
930
+ result , changed = com ._maybe_upcast_putmask (result , ~ mask , np . nan )
932
931
933
932
result = com ._fill_zeros (result , x , y , name , fill_zeros )
934
933
return result
0 commit comments