Skip to content

Commit 6f6c140

Browse files
committed
Added docstrings, depricated __iadd__, changed __add__ to use self.union()
1 parent 66b3b91 commit 6f6c140

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

doc/source/groupby.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ but the specified columns
133133

134134
.. ipython:: python
135135
136-
df.set_index(['A', 'B'])
137-
grouped = df.groupby(level=df.index.names.difference(['B'])
136+
df2 = df.set_index(['A', 'B'])
137+
grouped = df2.groupby(level=df2.index.names.difference(['B'])
138138
139139
These will split the DataFrame on its index (rows). We could also split by the
140140
columns:

doc/source/whatsnew/v0.20.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Check the :ref:`API Changes <whatsnew_0200.api_breaking>` and :ref:`deprecations
2626
New features
2727
~~~~~~~~~~~~
2828

29-
- Added difference from FrozenLists (:issue:`15475`)
29+
- Added ``.difference()`` method for FrozenLists (:issue:`15475`)
3030

3131
- Integration with the ``feather-format``, including a new top-level ``pd.read_feather()`` and ``DataFrame.to_feather()`` method, see :ref:`here <io.feather>`.
3232
- ``.str.replace`` now accepts a callable, as replacement, which is passed to ``re.sub`` (:issue:`15055`)

pandas/indexes/frozen.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ class FrozenList(PandasObject, list):
2828

2929
def __add__(self, other):
3030
warnings.warn("__add__ is deprecated, use union(...)", FutureWarning)
31-
if isinstance(other, tuple):
32-
other = list(other)
33-
return self.__class__(super(FrozenList, self).__add__(other))
31+
return self.union(other)
3432

35-
__iadd__ = __add__
33+
def __iadd__(self, other):
34+
warnings.warn("__iadd__ is deprecated, use union(...)", FutureWarning)
35+
return self.union(other)
3636

3737
# Python 2 compat
3838
def __getslice__(self, i, j):
@@ -84,11 +84,14 @@ def __repr__(self):
8484
pop = append = extend = remove = sort = insert = _disabled
8585

8686
def union(self, other):
87+
"""Returns a FrozenList with other concatenated to the end of self"""
8788
if isinstance(other, tuple):
8889
other = list(other)
8990
return self.__class__(super(FrozenList, self).__add__(other))
9091

9192
def difference(self, other):
93+
"""Returns a FrozenList with the same elements as self, but with elements
94+
that are also in other removed."""
9295
other = set(other)
9396
temp = [x for x in self if x not in other]
9497
return self.__class__(temp)

pandas/tests/indexes/test_frozen.py

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def setUp(self):
1414
self.container = FrozenList(self.lst)
1515
self.klass = FrozenList
1616

17+
def test_add(self):
18+
self.assert_produces_warning(FutureWarning)
19+
1720
def test_union(self):
1821
result = self.container.union((1, 2, 3))
1922
expected = FrozenList(self.lst + [1, 2, 3])

0 commit comments

Comments
 (0)