forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TYP/REF: define comparison methods non-dynamically (pandas-dev#36930)
- Loading branch information
1 parent
ffa1e2d
commit 3077c3a
Showing
8 changed files
with
138 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Methods that can be shared by many array-like classes or subclasses: | ||
Series | ||
Index | ||
ExtensionArray | ||
""" | ||
import operator | ||
|
||
from pandas.errors import AbstractMethodError | ||
|
||
from pandas.core.ops.common import unpack_zerodim_and_defer | ||
|
||
|
||
class OpsMixin: | ||
# ------------------------------------------------------------- | ||
# Comparisons | ||
|
||
def _cmp_method(self, other, op): | ||
raise AbstractMethodError(self) | ||
|
||
@unpack_zerodim_and_defer("__eq__") | ||
def __eq__(self, other): | ||
return self._cmp_method(other, operator.eq) | ||
|
||
@unpack_zerodim_and_defer("__ne__") | ||
def __ne__(self, other): | ||
return self._cmp_method(other, operator.ne) | ||
|
||
@unpack_zerodim_and_defer("__lt__") | ||
def __lt__(self, other): | ||
return self._cmp_method(other, operator.lt) | ||
|
||
@unpack_zerodim_and_defer("__le__") | ||
def __le__(self, other): | ||
return self._cmp_method(other, operator.le) | ||
|
||
@unpack_zerodim_and_defer("__gt__") | ||
def __gt__(self, other): | ||
return self._cmp_method(other, operator.gt) | ||
|
||
@unpack_zerodim_and_defer("__ge__") | ||
def __ge__(self, other): | ||
return self._cmp_method(other, operator.ge) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.