1
1
"""
2
2
Core eval alignment algorithms.
3
3
"""
4
-
5
4
from __future__ import annotations
6
5
7
6
from functools import (
8
7
partial ,
9
8
wraps ,
10
9
)
11
- from typing import TYPE_CHECKING
10
+ from typing import (
11
+ TYPE_CHECKING ,
12
+ Callable ,
13
+ )
12
14
import warnings
13
15
14
16
import numpy as np
15
17
16
- from pandas ._config .config import get_option
17
-
18
18
from pandas .errors import PerformanceWarning
19
19
from pandas .util ._exceptions import find_stack_level
20
20
28
28
from pandas .core .computation .common import result_type_many
29
29
30
30
if TYPE_CHECKING :
31
- from collections .abc import (
32
- Callable ,
33
- Sequence ,
34
- )
31
+ from collections .abc import Sequence
35
32
36
33
from pandas ._typing import F
37
34
@@ -113,7 +110,7 @@ def _align_core(terms):
113
110
ax , itm = axis , items
114
111
115
112
if not axes [ax ].is_ (itm ):
116
- axes [ax ] = axes [ax ].union (itm )
113
+ axes [ax ] = axes [ax ].join (itm , how = "outer" )
117
114
118
115
for i , ndim in ndims .items ():
119
116
for axis , items in zip (range (ndim ), axes ):
@@ -127,24 +124,20 @@ def _align_core(terms):
127
124
reindexer_size = len (reindexer )
128
125
129
126
ordm = np .log10 (max (1 , abs (reindexer_size - term_axis_size )))
130
- if (
131
- get_option ("performance_warnings" )
132
- and ordm >= 1
133
- and reindexer_size >= 10000
134
- ):
127
+ if ordm >= 1 and reindexer_size >= 10000 :
135
128
w = (
136
129
f"Alignment difference on axis { axis } is larger "
137
- f"than an order of magnitude on term { terms [i ].name !r } , "
130
+ f"than an order of magnitude on term { repr ( terms [i ].name ) } , "
138
131
f"by more than { ordm :.4g} ; performance may suffer."
139
132
)
140
133
warnings .warn (
141
134
w , category = PerformanceWarning , stacklevel = find_stack_level ()
142
135
)
143
136
144
- obj = ti .reindex (reindexer , axis = axis )
137
+ obj = ti .reindex (reindexer , axis = axis , copy = False )
145
138
terms [i ].update (obj )
146
139
147
- terms [i ].update (terms [i ].value . values )
140
+ terms [i ].update (terms [i ].value )
148
141
149
142
return typ , _zip_axes_from_type (typ , axes )
150
143
@@ -160,24 +153,19 @@ def align_terms(terms):
160
153
# can't iterate so it must just be a constant or single variable
161
154
if isinstance (terms .value , (ABCSeries , ABCDataFrame )):
162
155
typ = type (terms .value )
163
- name = terms .value .name if isinstance (terms .value , ABCSeries ) else None
164
- return typ , _zip_axes_from_type (typ , terms .value .axes ), name
165
- return np .result_type (terms .type ), None , None
156
+ return typ , _zip_axes_from_type (typ , terms .value .axes )
157
+ return np .result_type (terms .type ), None
166
158
167
159
# if all resolved variables are numeric scalars
168
160
if all (term .is_scalar for term in terms ):
169
- return result_type_many (* (term .value for term in terms )).type , None , None
170
-
171
- # if all input series have a common name, propagate it to the returned series
172
- names = {term .value .name for term in terms if isinstance (term .value , ABCSeries )}
173
- name = names .pop () if len (names ) == 1 else None
161
+ return result_type_many (* (term .value for term in terms )).type , None
174
162
175
163
# perform the main alignment
176
164
typ , axes = _align_core (terms )
177
- return typ , axes , name
165
+ return typ , axes
178
166
179
167
180
- def reconstruct_object (typ , obj , axes , dtype , name ):
168
+ def reconstruct_object (typ , obj , axes , dtype ):
181
169
"""
182
170
Reconstruct an object given its type, raw value, and possibly empty
183
171
(None) axes.
@@ -194,8 +182,8 @@ def reconstruct_object(typ, obj, axes, dtype, name):
194
182
Returns
195
183
-------
196
184
ret : typ
197
- An object of type `` typ`` with the value ` obj` and possible axes
198
- ` axes` .
185
+ An object of type typ with the value obj and possible axes
186
+ axes.
199
187
"""
200
188
try :
201
189
typ = typ .type
@@ -205,9 +193,7 @@ def reconstruct_object(typ, obj, axes, dtype, name):
205
193
res_t = np .result_type (obj .dtype , dtype )
206
194
207
195
if not isinstance (typ , partial ) and issubclass (typ , PandasObject ):
208
- if name is None :
209
- return typ (obj , dtype = res_t , ** axes )
210
- return typ (obj , dtype = res_t , name = name , ** axes )
196
+ return typ (obj , dtype = res_t , ** axes )
211
197
212
198
# special case for pathological things like ~True/~False
213
199
if hasattr (res_t , "type" ) and typ == np .bool_ and res_t != np .bool_ :
0 commit comments