88
99from pandas .errors import PerformanceWarning
1010
11- import pandas as pd
11+ from pandas .core .dtypes .generic import ABCDataFrame , ABCSeries
12+
1213from pandas .core .base import PandasObject
1314import 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
1516
1617
1718def _align_core_single_unary_op (term ):
@@ -49,7 +50,7 @@ def wrapper(terms):
4950
5051 # we don't have any pandas objects
5152 if not _any_pandas_objects (terms ):
52- return _result_type_many (* term_values ), None
53+ return result_type_many (* term_values ), None
5354
5455 return f (terms )
5556
@@ -60,7 +61,10 @@ def wrapper(terms):
6061def _align_core (terms ):
6162 term_index = [i for i , term in enumerate (terms ) if hasattr (term .value , "axes" )]
6263 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 )))
6468
6569 # initial axes are the axes of the largest-axis'd term
6670 biggest = terms [ndims .idxmax ()].value
@@ -70,7 +74,7 @@ def _align_core(terms):
7074 gt_than_one_axis = naxes > 1
7175
7276 for value in (terms [i ].value for i in term_index ):
73- is_series = isinstance (value , pd . Series )
77+ is_series = isinstance (value , ABCSeries )
7478 is_series_and_gt_one_axis = is_series and gt_than_one_axis
7579
7680 for axis , items in enumerate (value .axes ):
@@ -87,7 +91,7 @@ def _align_core(terms):
8791 ti = terms [i ].value
8892
8993 if hasattr (ti , "reindex" ):
90- transpose = isinstance (ti , pd . Series ) and naxes > 1
94+ transpose = isinstance (ti , ABCSeries ) and naxes > 1
9195 reindexer = axes [naxes - 1 ] if transpose else items
9296
9397 term_axis_size = len (ti .axes [axis ])
@@ -111,28 +115,28 @@ def _align_core(terms):
111115 return typ , _zip_axes_from_type (typ , axes )
112116
113117
114- def _align (terms ):
118+ def align_terms (terms ):
115119 """Align a set of terms"""
116120 try :
117121 # flatten the parse tree (a nested list, really)
118122 terms = list (com .flatten (terms ))
119123 except TypeError :
120124 # 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 ) ):
122126 typ = type (terms .value )
123127 return typ , _zip_axes_from_type (typ , terms .value .axes )
124128 return np .result_type (terms .type ), None
125129
126130 # if all resolved variables are numeric scalars
127131 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
129133
130134 # perform the main alignment
131135 typ , axes = _align_core (terms )
132136 return typ , axes
133137
134138
135- def _reconstruct_object (typ , obj , axes , dtype ):
139+ def reconstruct_object (typ , obj , axes , dtype ):
136140 """
137141 Reconstruct an object given its type, raw value, and possibly empty
138142 (None) axes.
0 commit comments