-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Unary plus operator (Issue #16073) #16106
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
Changes from all commits
7e71501
af7512a
38d48c8
2ec64d2
f10e3be
2c09624
8f4d7ca
c658f7f
d932379
0ab9979
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -859,6 +859,19 @@ def _indexed_same(self, other): | |
return all([self._get_axis(a).equals(other._get_axis(a)) | ||
for a in self._AXIS_ORDERS]) | ||
|
||
def __pos__(self): | ||
values = _values_from_object(self) | ||
if values.dtype == np.bool_: | ||
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. something like:
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. add the same logic to |
||
arr = values | ||
else: | ||
if (len(values) > 0): | ||
try: | ||
-values[0] | ||
except TypeError: | ||
raise TypeError("`+` only works on data types that support `-`") | ||
arr = operator.pos(values) | ||
return self.__array_wrap__(arr) | ||
|
||
def __neg__(self): | ||
values = _values_from_object(self) | ||
if values.dtype == np.bool_: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -343,9 +343,15 @@ def test_logical_with_nas(self): | |
expected = Series([True, True]) | ||
assert_series_equal(result, expected) | ||
|
||
def test_pos(self): | ||
try: | ||
assert_frame_equal(+self.frame, self.frame.apply(lambda x: +self.frame)) | ||
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. dont' test like this. instead use a couple of sample frames that have singular dtypes (can be a single column). test the valid ones via |
||
except TypeError: | ||
if not (len(self.frame) > 0 and isinstance(self.frame[0], pd.Timestamp)): | ||
raise | ||
|
||
def test_neg(self): | ||
# what to do? | ||
assert_frame_equal(-self.frame, -1 * self.frame) | ||
assert_frame_equal(-self.frame, self.frame.apply(lambda x: -self.frame)) | ||
|
||
def test_invert(self): | ||
assert_frame_equal(-(self.frame < 0), ~(self.frame < 0)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,8 +91,15 @@ def check(series, other, check_reverse=False): | |
check(self.ts, 5, check_reverse=True) | ||
check(tm.makeFloatSeries(), tm.makeFloatSeries(), check_reverse=True) | ||
|
||
def test_pos(self): | ||
try: | ||
assert_series_equal(+self.series, self.series.apply(lambda x: +x)) | ||
except TypeError: | ||
if not (len(self.frame) > 0 and isinstance(self.frame[0], pd.Timestampe)): | ||
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 |
||
raise | ||
|
||
def test_neg(self): | ||
assert_series_equal(-self.series, -1 * self.series) | ||
assert_series_equal(-self.series, self.series.apply(lambda x: -x)) | ||
|
||
def test_invert(self): | ||
assert_series_equal(-(self.series < 0), ~(self.series < 0)) | ||
|
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.
don't change other things in the file
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'm not certain why this happened. The rest of the diff shows that the same identical line is added again, thus making no actual changes to the file