-
- Notifications
You must be signed in to change notification settings - Fork 19.4k
ENH: Implement EA unary ops #23313
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
Closed
Closed
ENH: Implement EA unary ops #23313
Changes from all commits
Commits
Show all changes
25 commits Select commit Hold shift + click to select a range
4188e9f ENH: Implement EA unary ops
sinhrks 6e5cf3d Fixed test for older NumPy ver
sinhrks 3b3003f Fixed tests for latest numpy
sinhrks e0b37ae updated doc
sinhrks 6476d0d Additional fixes
sinhrks 528e4d1 Remove unary method from DatetimeArray
sinhrks dbdce23 move __pos__ logic to ExtensionArray
sinhrks af84599 Merge remote-tracking branch 'upstream/master' into unary
WillAyd b0975f4 Reverted bad merge of 24 whatsnew
WillAyd 8e3638c Removed Panel-specific code
WillAyd 63430e7 Added stdlib operator import
WillAyd 9fe6085 Merge remote-tracking branch 'upstream/master' into unary
WillAyd b6430f1 Removed old np13 check
WillAyd 736fc27 Fixed wrong error msg expectation
WillAyd 87b8cab lint fixup
WillAyd c6437ba Merge remote-tracking branch 'upstream/master' into unary
WillAyd 91a7fec Added warnings catch for operator pos
WillAyd b221fd0 lint fixup
WillAyd 0afef3c Reverted warnings catch
WillAyd 4c322b6 Reimplemented warnings catch for np dev
WillAyd 2b480be test fixup
WillAyd ad62830 Used OrderedDict for py35 compat
WillAyd 0d6e0c5 Changed to tm.assert_produces_warning
WillAyd 4f6d656 Merge remote-tracking branch 'upstream/master' into unary
WillAyd 536d002 Fixed bad imports
WillAyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| | @@ -223,6 +223,20 @@ def all_compare_operators(request): | |
| return request.param | ||
| | ||
| | ||
| @pytest.fixture(params=['__pos__', '__neg__', '__inv__', '__invert__', | ||
| '__abs__']) | ||
| def all_unary_operators(request): | ||
| """ | ||
| Fixture for dunder names for common unary operations | ||
| | ||
| * + | ||
| * - | ||
| * ~ | ||
| * abs | ||
| """ | ||
| return request.param | ||
| | ||
| | ||
| @pytest.fixture(params=['__le__', '__lt__', '__ge__', '__gt__']) | ||
| def compare_operators_no_eq_ne(request): | ||
| """ | ||
| | @@ -413,6 +427,7 @@ def tz_aware_fixture(request): | |
| SIGNED_EA_INT_DTYPES = ["Int8", "Int16", "Int32", "Int64"] | ||
| ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES | ||
| ALL_EA_INT_DTYPES = UNSIGNED_EA_INT_DTYPES + SIGNED_EA_INT_DTYPES | ||
| ALL_NUMPY_EA_INT_DTYPES = ALL_INT_DTYPES + ALL_EA_INT_DTYPES | ||
| Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is fine | ||
| | ||
| FLOAT_DTYPES = [float, "float32", "float64"] | ||
| COMPLEX_DTYPES = [complex, "complex64", "complex128"] | ||
| | @@ -556,6 +571,51 @@ def any_int_dtype(request): | |
| return request.param | ||
| | ||
| | ||
| @pytest.fixture(params=ALL_EA_INT_DTYPES) | ||
| def any_ea_int_dtype(request): | ||
| """ | ||
| Parameterized fixture for any integer dtype. | ||
| | ||
| * 'Int8' | ||
| * 'UInt8' | ||
| * 'Int16' | ||
| * 'UInt16' | ||
| * 'Int32' | ||
| * 'UInt32' | ||
| * 'Int64' | ||
| * 'UInt64' | ||
| """ | ||
| | ||
| return request.param | ||
| | ||
| | ||
| @pytest.fixture(params=ALL_NUMPY_EA_INT_DTYPES) | ||
| def any_numpy_ea_int_dtype(request): | ||
| """ | ||
| Parameterized fixture for any integer dtype. | ||
| | ||
| * int | ||
| * 'int8' | ||
| * 'uint8' | ||
| * 'int16' | ||
| * 'uint16' | ||
| * 'int32' | ||
| * 'uint32' | ||
| * 'int64' | ||
| * 'uint64' | ||
| * 'Int8' | ||
| * 'UInt8' | ||
| * 'Int16' | ||
| * 'UInt16' | ||
| * 'Int32' | ||
| * 'UInt32' | ||
| * 'Int64' | ||
| * 'UInt64' | ||
| """ | ||
| | ||
| return request.param | ||
| | ||
| | ||
| @pytest.fixture(params=ALL_REAL_DTYPES) | ||
| def any_real_dtype(request): | ||
| """ | ||
| | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| | @@ -785,6 +785,10 @@ def _add_delta(self, delta): | |
| new_values = super()._add_delta(delta) | ||
| return type(self)._from_sequence(new_values, tz=self.tz, freq='infer') | ||
| | ||
| def __pos__(self): | ||
| raise TypeError("Unary plus expects numeric dtype, not {}" | ||
| .format(self.dtype)) | ||
| | ||
| Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same for PeriodArray? | ||
| # ----------------------------------------------------------------- | ||
| # Timezone Conversion and Localization Methods | ||
| | ||
| | ||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| | @@ -733,6 +733,9 @@ def __rdivmod__(self, other): | |
| return res1, res2 | ||
| | ||
| # Note: TimedeltaIndex overrides this in call to cls._add_numeric_methods | ||
| def __pos__(self): | ||
| return self.copy() | ||
| Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be a copy or view? | ||
| | ||
| def __neg__(self): | ||
| if self.freq is not None: | ||
| return type(self)(-self._data, freq=-self.freq) | ||
| | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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 this have a name reflecting the fact that these are the strings and not operator.pos, operator.neg, etc?