Skip to content

Commit

Permalink
Added __isub__ and groupby example to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
benthayer committed Feb 25, 2017
1 parent cd73faa commit 2fad2f7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions doc/source/groupby.rst
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ We could naturally group by either the ``A`` or ``B`` columns or both:
grouped = df.groupby('A')
grouped = df.groupby(['A', 'B'])
If we also have a MultiIndex on columns ``A`` and ``B``, we can group by all
but the specified columns

.. ipython:: python
df.set_index(['A', 'B'])
grouped = df.groupby(level=df.index.names - ['B'])
These will split the DataFrame on its index (rows). We could also split by the
columns:

Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Check the :ref:`API Changes <whatsnew_0200.api_breaking>` and :ref:`deprecations
New features
~~~~~~~~~~~~

- Added subtraction from FrozenLists (:issue:`15475`)
- Added difference from FrozenLists (:issue:`15475`)

- Integration with the ``feather-format``, including a new top-level ``pd.read_feather()`` and ``DataFrame.to_feather()`` method, see :ref:`here <io.feather>`.
- ``.str.replace`` now accepts a callable, as replacement, which is passed to ``re.sub`` (:issue:`15055`)
Expand Down
2 changes: 2 additions & 0 deletions pandas/indexes/frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def __sub__(self, other):
temp = [x for x in self if x not in other]
return self.__class__(temp)

__isub__ = __sub__

# Python 2 compat
def __getslice__(self, i, j):
return self.__class__(super(FrozenList, self).__getslice__(i, j))
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/indexes/test_frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def test_inplace(self):
# other shouldn't be mutated
self.check_result(r, self.lst)

def test_inplace_sub(self):
q = r = self.container
q -= [5]
self.check_result(q, self.container - [5])
# other shouldn't be mutated
self.check_result(r, self.lst)


class TestFrozenNDArray(CheckImmutable, CheckStringMixin, tm.TestCase):
mutable_methods = ('put', 'itemset', 'fill')
Expand Down

0 comments on commit 2fad2f7

Please sign in to comment.