@@ -187,7 +187,7 @@ class NDFrame(PandasObject, SelectionMixin):
187
187
"ix" ,
188
188
]
189
189
) # type: FrozenSet[str]
190
- _metadata = ["allows_duplicate_labels" ] # type: List[str]
190
+ _metadata = [] # type: List[str]
191
191
_is_copy = None
192
192
_data = None # type: BlockManager
193
193
@@ -224,12 +224,16 @@ def __init__(
224
224
object .__setattr__ (self , "_is_copy" , None )
225
225
object .__setattr__ (self , "_data" , data )
226
226
object .__setattr__ (self , "_item_cache" , {})
227
- object .__setattr__ (self , "allows_duplicate_labels" , allow_duplicate_labels )
228
227
if attrs is None :
229
228
attrs = {}
230
229
else :
231
230
attrs = dict (attrs )
231
+ # need to add it to the dict here, since NDFrame.__setattr__
232
+ # also calls NDFrame.__getattr__...
233
+ # attrs['allows_duplicate_labels'] = allow_duplicate_labels
232
234
object .__setattr__ (self , "_attrs" , attrs )
235
+ object .__setattr__ (self , "allows_duplicate_labels" , allow_duplicate_labels )
236
+ # self.allows_duplicate_labels = allow_duplicate_labels
233
237
234
238
def _init_mgr (self , mgr , axes = None , dtype = None , copy = False ):
235
239
""" passed a manager and a axes dict """
@@ -251,21 +255,6 @@ def _init_mgr(self, mgr, axes=None, dtype=None, copy=False):
251
255
# ----------------------------------------------------------------------
252
256
253
257
@property
254
- def allows_duplicate_labels (self ):
255
- """
256
- Whether this object allows duplicate labels.
257
- """
258
- return self ._allows_duplicate_labels
259
-
260
- @allows_duplicate_labels .setter
261
- def allows_duplicate_labels (self , value : bool ):
262
- value = bool (value )
263
- if not value :
264
- for ax in self .axes :
265
- ax ._maybe_check_unique ()
266
-
267
- self ._allows_duplicate_labels = value
268
-
269
258
def attrs (self ) -> Dict [Hashable , Any ]:
270
259
"""
271
260
Dictionary of global attributes on this object.
@@ -278,6 +267,22 @@ def attrs(self) -> Dict[Hashable, Any]:
278
267
def attrs (self , value : Mapping [Hashable , Any ]) -> None :
279
268
self ._attrs = dict (value )
280
269
270
+ @property
271
+ def allows_duplicate_labels (self ) -> bool :
272
+ """
273
+ Whether this object allows duplicate labels.
274
+ """
275
+ return self .attrs ["allows_duplicate_labels" ]
276
+
277
+ @allows_duplicate_labels .setter
278
+ def allows_duplicate_labels (self , value : bool ):
279
+ value = bool (value )
280
+ if not value :
281
+ for ax in self .axes :
282
+ ax ._maybe_check_unique ()
283
+
284
+ self .attrs ["allows_duplicate_labels" ] = value
285
+
281
286
@property
282
287
def is_copy (self ):
283
288
"""
@@ -3655,7 +3660,8 @@ class animal locomotion
3655
3660
index = self .columns ,
3656
3661
name = self .index [loc ],
3657
3662
dtype = new_values .dtype ,
3658
- ).__finalize__ (self , method = "xs" )
3663
+ )
3664
+ result .__finalize__ (self , method = "xs" )
3659
3665
3660
3666
else :
3661
3667
result = self .iloc [loc ]
@@ -5276,18 +5282,18 @@ def finalize_name(objs):
5276
5282
5277
5283
duplicate_labels = "allows_duplicate_labels"
5278
5284
5279
- # import pdb; pdb.set_trace()
5280
5285
if isinstance (other , NDFrame ):
5281
- for name in other .attrs :
5282
- self .attrs [name ] = other .attrs [name ]
5286
+ for name , value in other .attrs .items ():
5287
+ # Need to think about this...
5288
+ if name == "allows_duplicate_labels" :
5289
+ self .allows_duplicate_labels = value
5290
+ elif name in self .attrs :
5291
+ self .attrs [name ] = other .attrs [name ]
5292
+
5283
5293
# For subclasses using _metadata.
5284
5294
for name in self ._metadata :
5285
- if name == "name" and getattr (other , "ndim" , None ) == 1 :
5286
- # Calling hasattr(other, 'name') is bad for DataFrames with
5287
- # a name column.
5288
- object .__setattr__ (self , name , getattr (other , name , None ))
5289
- elif name != "name" :
5290
- object .__setattr__ (self , name , getattr (other , name , None ))
5295
+ object .__setattr__ (self , name , getattr (other , name , None ))
5296
+
5291
5297
elif method == "concat" :
5292
5298
assert isinstance (other , _Concatenator )
5293
5299
self .allows_duplicate_labels = merge_all (other .objs , duplicate_labels )
@@ -5296,7 +5302,7 @@ def finalize_name(objs):
5296
5302
self .allows_duplicate_labels = merge_all (
5297
5303
(other .left , other .right ), duplicate_labels
5298
5304
)
5299
- elif method in {"combine_const" , "combine_frame" }:
5305
+ elif method in {"combine_const" , "combine_frame" , "combine_series_frame" }:
5300
5306
assert isinstance (other , tuple )
5301
5307
self .allows_duplicate_labels = merge_all (other , duplicate_labels )
5302
5308
elif method == "align_series" :
@@ -9078,10 +9084,9 @@ def _align_series(
9078
9084
right .index = join_index
9079
9085
9080
9086
# TODO: Determine the expected behavior here. Should these affect eachother?
9081
- return (
9082
- left .__finalize__ ((self , other ), method = "align_series" ),
9083
- right .__finalize__ ((other , self ), method = "align_series" ),
9084
- )
9087
+ left .__finalize__ ((self , other ), method = "align_series" )
9088
+ right .__finalize__ ((other , self ), method = "align_series" )
9089
+ return left , right
9085
9090
9086
9091
def _where (
9087
9092
self ,
@@ -10032,7 +10037,9 @@ def abs(self):
10032
10037
2 6 30 -30
10033
10038
3 7 40 -50
10034
10039
"""
10035
- return np .abs (self ).__finalize__ (self )
10040
+ result = np .abs (self )
10041
+ result .__finalize__ (self )
10042
+ return result
10036
10043
10037
10044
def describe (self , percentiles = None , include = None , exclude = None ):
10038
10045
"""
0 commit comments