8
8
9
9
from pandas .errors import PerformanceWarning
10
10
11
- import pandas as pd
11
+ from pandas .core .dtypes .generic import ABCDataFrame , ABCSeries
12
+
12
13
from pandas .core .base import PandasObject
13
14
import pandas .core .common as com
14
- from pandas .core .computation .common import _result_type_many
15
+ from pandas .core .computation .common import result_type_many
15
16
16
17
17
18
def _align_core_single_unary_op (term ):
@@ -49,7 +50,7 @@ def wrapper(terms):
49
50
50
51
# we don't have any pandas objects
51
52
if not _any_pandas_objects (terms ):
52
- return _result_type_many (* term_values ), None
53
+ return result_type_many (* term_values ), None
53
54
54
55
return f (terms )
55
56
@@ -60,7 +61,10 @@ def wrapper(terms):
60
61
def _align_core (terms ):
61
62
term_index = [i for i , term in enumerate (terms ) if hasattr (term .value , "axes" )]
62
63
term_dims = [terms [i ].value .ndim for i in term_index ]
63
- ndims = pd .Series (dict (zip (term_index , term_dims )))
64
+
65
+ from pandas import Series
66
+
67
+ ndims = Series (dict (zip (term_index , term_dims )))
64
68
65
69
# initial axes are the axes of the largest-axis'd term
66
70
biggest = terms [ndims .idxmax ()].value
@@ -70,7 +74,7 @@ def _align_core(terms):
70
74
gt_than_one_axis = naxes > 1
71
75
72
76
for value in (terms [i ].value for i in term_index ):
73
- is_series = isinstance (value , pd . Series )
77
+ is_series = isinstance (value , ABCSeries )
74
78
is_series_and_gt_one_axis = is_series and gt_than_one_axis
75
79
76
80
for axis , items in enumerate (value .axes ):
@@ -87,7 +91,7 @@ def _align_core(terms):
87
91
ti = terms [i ].value
88
92
89
93
if hasattr (ti , "reindex" ):
90
- transpose = isinstance (ti , pd . Series ) and naxes > 1
94
+ transpose = isinstance (ti , ABCSeries ) and naxes > 1
91
95
reindexer = axes [naxes - 1 ] if transpose else items
92
96
93
97
term_axis_size = len (ti .axes [axis ])
@@ -111,28 +115,28 @@ def _align_core(terms):
111
115
return typ , _zip_axes_from_type (typ , axes )
112
116
113
117
114
- def _align (terms ):
118
+ def align_terms (terms ):
115
119
"""Align a set of terms"""
116
120
try :
117
121
# flatten the parse tree (a nested list, really)
118
122
terms = list (com .flatten (terms ))
119
123
except TypeError :
120
124
# can't iterate so it must just be a constant or single variable
121
- if isinstance (terms .value , pd . core . generic . NDFrame ):
125
+ if isinstance (terms .value , ( ABCSeries , ABCDataFrame ) ):
122
126
typ = type (terms .value )
123
127
return typ , _zip_axes_from_type (typ , terms .value .axes )
124
128
return np .result_type (terms .type ), None
125
129
126
130
# if all resolved variables are numeric scalars
127
131
if all (term .is_scalar for term in terms ):
128
- return _result_type_many (* (term .value for term in terms )).type , None
132
+ return result_type_many (* (term .value for term in terms )).type , None
129
133
130
134
# perform the main alignment
131
135
typ , axes = _align_core (terms )
132
136
return typ , axes
133
137
134
138
135
- def _reconstruct_object (typ , obj , axes , dtype ):
139
+ def reconstruct_object (typ , obj , axes , dtype ):
136
140
"""
137
141
Reconstruct an object given its type, raw value, and possibly empty
138
142
(None) axes.
0 commit comments