-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Added FrozenList subtraction #15506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added FrozenList subtraction #15506
Conversation
pandas/indexes/frozen.py
Outdated
def __sub__(self, other): | ||
other = set(other) | ||
temp = [x for x in self if x not in other] | ||
return self.__class__(temp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add isub as well (and a test)
doc/source/whatsnew/v0.20.0.txt
Outdated
@@ -26,6 +26,8 @@ Check the :ref:`API Changes <whatsnew_0200.api_breaking>` and :ref:`deprecations | |||
New features | |||
~~~~~~~~~~~~ | |||
|
|||
- Added subtraction from FrozenLists (:issue:`15475`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is called difference
i think might be nice to add an example to th docs as well
Codecov Report
@@ Coverage Diff @@
## master #15506 +/- ##
==========================================
- Coverage 91.06% 91.04% -0.03%
==========================================
Files 136 136
Lines 49099 49182 +83
==========================================
+ Hits 44714 44779 +65
- Misses 4385 4403 +18
Continue to review full report at Codecov.
|
doc/source/groupby.rst
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a versionadded tag here
pandas/tests/indexes/test_frozen.py
Outdated
result = FrozenList([1, 2, 3, 2]) - [2] | ||
expected = FrozenList([1, 3]) | ||
self.check_result(result, expected) | ||
|
||
def test_inplace(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you rename this to make consistent
…ce_add for consistency
I want to raise some concern regarding adding this feature (without wanting to dismiss your effort @bthayer2365 !). I think we should think about this some more. Adding this would introduce a discrepancy between index level names and column names, while we actually try to lessen the gap (eg by being able to specify an index level name in places where you can specify a column name). This is actually a feature we removed from column names, in favor of the |
no conceptual problem with making these real setops, e.g. |
Would you like me to change |
yes; u will have to deprecate the add though |
To do that, do I just decorate it with |
that should work (and add in whatsnew as well) |
doc/source/groupby.rst
Outdated
|
||
.. ipython:: python | ||
|
||
df.set_index(['A', 'B']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this won't work as it returns a new object, instead something like
df2 = df.set_index(['A', 'B'])
grouped = df2.groupby(level=....)
doc/source/whatsnew/v0.20.0.txt
Outdated
@@ -26,6 +26,8 @@ Check the :ref:`API Changes <whatsnew_0200.api_breaking>` and :ref:`deprecations | |||
New features | |||
~~~~~~~~~~~~ | |||
|
|||
- Added difference from FrozenLists (:issue:`15475`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.difference()
method for FrozenList
pandas/indexes/frozen.py
Outdated
@@ -25,6 +27,7 @@ class FrozenList(PandasObject, list): | |||
# typechecks | |||
|
|||
def __add__(self, other): | |||
warnings.warn("__add__ is deprecated, use union(...)", FutureWarning) | |||
if isinstance(other, tuple): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return self.union(other)
pandas/indexes/frozen.py
Outdated
@@ -80,6 +83,16 @@ def __repr__(self): | |||
__setitem__ = __setslice__ = __delitem__ = __delslice__ = _disabled | |||
pop = append = extend = remove = sort = insert = _disabled | |||
|
|||
def union(self, other): | |||
if isinstance(other, tuple): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a doc-string
pandas/indexes/frozen.py
Outdated
return self.__class__(super(FrozenList, self).__add__(other)) | ||
|
||
def difference(self, other): | ||
other = set(other) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
pandas/tests/indexes/test_frozen.py
Outdated
@@ -14,21 +14,20 @@ def setUp(self): | |||
self.container = FrozenList(self.lst) | |||
self.klass = FrozenList | |||
|
|||
def test_add(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a test for assert_produces_warning(FutureWarning)
for the deprecation of __add__
pandas/indexes/frozen.py
Outdated
def union(self, other): | ||
if isinstance(other, tuple): | ||
other = list(other) | ||
return self.__class__(super(FrozenList, self).__add__(other)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think __iadd__
is also defined? if so, deprecate that as well (no replacement, just a deprecation)
Anything else? All tests passed 👍 |
thanks @bthayer2365 |
closes pandas-dev#15475 Author: Ben Thayer <[email protected]> Author: bthayer2365 <[email protected]> Closes pandas-dev#15506 from bthayer2365/frozen-index and squashes the following commits: 428a1b3 [Ben Thayer] Added __iadd__ test, fixed whatsnew 84ba405 [Ben Thayer] Merge branch 'master' of github.com:pandas-dev/pandas into frozen-index 8dbde1e [Ben Thayer] Rebased to upstream/master 6f6c140 [Ben Thayer] Added docstrings, depricated __iadd__, changed __add__ to use self.union() 66b3b91 [Ben Thayer] Fixed issue number 3d6cee5 [Ben Thayer] Depricated __add__ in favor of union ccd75c7 [Ben Thayer] Changed __sub__ to difference cd7de26 [Ben Thayer] Added versionadded tag in docs and renamed test_inplace to test_inplace_add for consistency 0ea8d21 [Ben Thayer] Added __isub__ and groupby example to docs 79dd958 [Ben Thayer] Updated whatsnew to reflect changes 0fc7e19 [Ben Thayer] Removed whitespace 73564ab [Ben Thayer] Added FrozenList subtraction fee7a7d [bthayer2365] Merge branch 'master' into frozen-index 6a2b48d [Ben Thayer] Added docstrings, depricated __iadd__, changed __add__ to use self.union() 2ab85cb [Ben Thayer] Fixed issue number cb95089 [Ben Thayer] Depricated __add__ in favor of union 2e43849 [Ben Thayer] Changed __sub__ to difference fdcfbbb [Ben Thayer] Added versionadded tag in docs and renamed test_inplace to test_inplace_add for consistency 2fad2f7 [Ben Thayer] Added __isub__ and groupby example to docs cd73faa [Ben Thayer] Updated whatsnew to reflect changes f6381a8 [Ben Thayer] Removed whitespace ada7cda [Ben Thayer] Added FrozenList subtraction
@bthayer2365 Great job! Thanks for your contribution. |
Glad I could help! |
See #15559. This temporarily reverts #15506, to see if this fixes the doc build slowdown. Author: Joris Van den Bossche <[email protected]> Closes #15566 from jorisvandenbossche/revert and squashes the following commits: befd858 [Joris Van den Bossche] Revert "ENH: Added FrozenList difference setop" 527ded9 [Joris Van den Bossche] Revert "TST: remove deprecated usages of FrozenList.__add__ from test code"
closes pandas-dev#15475 Author: Ben Thayer <[email protected]> Author: bthayer2365 <[email protected]> Closes pandas-dev#15506 from bthayer2365/frozen-index and squashes the following commits: 428a1b3 [Ben Thayer] Added __iadd__ test, fixed whatsnew 84ba405 [Ben Thayer] Merge branch 'master' of github.com:pandas-dev/pandas into frozen-index 8dbde1e [Ben Thayer] Rebased to upstream/master 6f6c140 [Ben Thayer] Added docstrings, depricated __iadd__, changed __add__ to use self.union() 66b3b91 [Ben Thayer] Fixed issue number 3d6cee5 [Ben Thayer] Depricated __add__ in favor of union ccd75c7 [Ben Thayer] Changed __sub__ to difference cd7de26 [Ben Thayer] Added versionadded tag in docs and renamed test_inplace to test_inplace_add for consistency 0ea8d21 [Ben Thayer] Added __isub__ and groupby example to docs 79dd958 [Ben Thayer] Updated whatsnew to reflect changes 0fc7e19 [Ben Thayer] Removed whitespace 73564ab [Ben Thayer] Added FrozenList subtraction fee7a7d [bthayer2365] Merge branch 'master' into frozen-index 6a2b48d [Ben Thayer] Added docstrings, depricated __iadd__, changed __add__ to use self.union() 2ab85cb [Ben Thayer] Fixed issue number cb95089 [Ben Thayer] Depricated __add__ in favor of union 2e43849 [Ben Thayer] Changed __sub__ to difference fdcfbbb [Ben Thayer] Added versionadded tag in docs and renamed test_inplace to test_inplace_add for consistency 2fad2f7 [Ben Thayer] Added __isub__ and groupby example to docs cd73faa [Ben Thayer] Updated whatsnew to reflect changes f6381a8 [Ben Thayer] Removed whitespace ada7cda [Ben Thayer] Added FrozenList subtraction
closes pandas-dev#15475 Author: Ben Thayer <[email protected]> Author: bthayer2365 <[email protected]> Closes pandas-dev#15506 from bthayer2365/frozen-index and squashes the following commits: 428a1b3 [Ben Thayer] Added __iadd__ test, fixed whatsnew 84ba405 [Ben Thayer] Merge branch 'master' of github.com:pandas-dev/pandas into frozen-index 8dbde1e [Ben Thayer] Rebased to upstream/master 6f6c140 [Ben Thayer] Added docstrings, depricated __iadd__, changed __add__ to use self.union() 66b3b91 [Ben Thayer] Fixed issue number 3d6cee5 [Ben Thayer] Depricated __add__ in favor of union ccd75c7 [Ben Thayer] Changed __sub__ to difference cd7de26 [Ben Thayer] Added versionadded tag in docs and renamed test_inplace to test_inplace_add for consistency 0ea8d21 [Ben Thayer] Added __isub__ and groupby example to docs 79dd958 [Ben Thayer] Updated whatsnew to reflect changes 0fc7e19 [Ben Thayer] Removed whitespace 73564ab [Ben Thayer] Added FrozenList subtraction fee7a7d [bthayer2365] Merge branch 'master' into frozen-index 6a2b48d [Ben Thayer] Added docstrings, depricated __iadd__, changed __add__ to use self.union() 2ab85cb [Ben Thayer] Fixed issue number cb95089 [Ben Thayer] Depricated __add__ in favor of union 2e43849 [Ben Thayer] Changed __sub__ to difference fdcfbbb [Ben Thayer] Added versionadded tag in docs and renamed test_inplace to test_inplace_add for consistency 2fad2f7 [Ben Thayer] Added __isub__ and groupby example to docs cd73faa [Ben Thayer] Updated whatsnew to reflect changes f6381a8 [Ben Thayer] Removed whitespace ada7cda [Ben Thayer] Added FrozenList subtraction
See pandas-dev#15559. This temporarily reverts pandas-dev#15506, to see if this fixes the doc build slowdown. Author: Joris Van den Bossche <[email protected]> Closes pandas-dev#15566 from jorisvandenbossche/revert and squashes the following commits: befd858 [Joris Van den Bossche] Revert "ENH: Added FrozenList difference setop" 527ded9 [Joris Van den Bossche] Revert "TST: remove deprecated usages of FrozenList.__add__ from test code"
Re-attempt of pandas-devgh-15506. Closes pandas-devgh-15475.
Re-attempt of pandas-devgh-15506. Closes pandas-devgh-15475.
Re-attempt of pandas-devgh-15506. Closes pandas-devgh-15475.
Re-attempt of pandas-devgh-15506. Closes pandas-devgh-15475.
Re-attempt of pandas-devgh-15506. Closes pandas-devgh-15475.
Re-attempt of pandas-devgh-15506. Closes pandas-devgh-15475.
Re-attempt of pandas-devgh-15506. Closes pandas-devgh-15475.
git diff upstream/master | flake8 --diff