Skip to content

Commit cb95089

Browse files
committed
Depricated __add__ in favor of union
1 parent 2e43849 commit cb95089

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

doc/source/whatsnew/v0.20.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ Deprecations
486486
- ``DataFrame.astype()`` has deprecated the ``raise_on_error`` parameter in favor of ``errors`` (:issue:`14878`)
487487
- ``Series.sortlevel`` and ``DataFrame.sortlevel`` have been deprecated in favor of ``Series.sort_index`` and ``DataFrame.sort_index`` (:issue:`15099`)
488488
- importing ``concat`` from ``pandas.tools.merge`` has been deprecated in favor of imports from the ``pandas`` namespace. This should only affect explict imports (:issue:`15358`)
489-
489+
- ``FrozenList.__add__`` has been depricated in favor of ``FrozenList.union`` (:issue: `15506`)
490490
.. _whatsnew_0200.prior_deprecations:
491491

492492
Removal of prior version deprecations/changes

pandas/indexes/frozen.py

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from pandas.types.cast import _coerce_indexer_dtype
1414
from pandas.formats.printing import pprint_thing
1515

16+
import warnings
17+
1618

1719
class FrozenList(PandasObject, list):
1820

@@ -25,6 +27,7 @@ class FrozenList(PandasObject, list):
2527
# typechecks
2628

2729
def __add__(self, other):
30+
warnings.warn("__add__ is deprecated, use union(...)", FutureWarning)
2831
if isinstance(other, tuple):
2932
other = list(other)
3033
return self.__class__(super(FrozenList, self).__add__(other))
@@ -80,6 +83,11 @@ def __repr__(self):
8083
__setitem__ = __setslice__ = __delitem__ = __delslice__ = _disabled
8184
pop = append = extend = remove = sort = insert = _disabled
8285

86+
def union(self, other):
87+
if isinstance(other, tuple):
88+
other = list(other)
89+
return self.__class__(super(FrozenList, self).__add__(other))
90+
8391
def difference(self, other):
8492
other = set(other)
8593
temp = [x for x in self if x not in other]

pandas/tests/indexes/test_frozen.py

+2-13
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,11 @@ def setUp(self):
1414
self.container = FrozenList(self.lst)
1515
self.klass = FrozenList
1616

17-
def test_add(self):
18-
result = self.container + (1, 2, 3)
17+
def test_union(self):
18+
result = self.container.union((1, 2, 3))
1919
expected = FrozenList(self.lst + [1, 2, 3])
2020
self.check_result(result, expected)
2121

22-
result = (1, 2, 3) + self.container
23-
expected = FrozenList([1, 2, 3] + self.lst)
24-
self.check_result(result, expected)
25-
26-
def test_inplace_add(self):
27-
q = r = self.container
28-
q += [5]
29-
self.check_result(q, self.lst + [5])
30-
# other shouldn't be mutated
31-
self.check_result(r, self.lst)
32-
3322
def test_difference(self):
3423
result = self.container.difference([2])
3524
expected = FrozenList([1, 3, 4, 5])

0 commit comments

Comments
 (0)