-
-
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 4 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 |
---|---|---|
|
@@ -213,8 +213,7 @@ See :ref:`the docs here <io.pickle.compression>` | |
|
||
Using an explicit compression type | ||
|
||
.. ipython:: python | ||
|
||
.. ipython:: python | ||
df.to_pickle("data.pkl.compress", compression="gzip") | ||
rt = pd.read_pickle("data.pkl.compress", compression="gzip") | ||
rt | ||
|
@@ -1196,6 +1195,8 @@ Other API Changes | |
- ``DataFrame`` and ``Panel`` constructors with invalid input will now raise ``ValueError`` rather than ``pandas.core.common.PandasError``, if called with scalar inputs and not axes; The exception ``PandasError`` is removed as well. (:issue:`15541`) | ||
- The exception ``pandas.core.common.AmbiguousIndexError`` is removed as it is not referenced (:issue:`15541`) | ||
|
||
- `Series` and `DataFrame` now have unary plus operators (:issue:`16073`). The plus operator behaves consistently with the unary minus operator. | ||
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. use double backticks here around Series, DataFrame. Put the issue reference at the end. |
||
|
||
|
||
.. _whatsnew_0200.privacy: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -859,6 +859,14 @@ 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 #To remain consistent with __neg__ | ||
else: | ||
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 |
---|---|---|
|
@@ -91,6 +91,9 @@ 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): | ||
assert_series_equal(+self.series, 1 * self.series) #Ensures no rounding issues | ||
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. comment is not necessary |
||
|
||
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 a couple of raise assertion on strings 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 would technically work on datetimes, but I think we should disallow this (pls add tests for 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. e.g.
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.
I want [12] still to raise after this change. |
||
def test_neg(self): | ||
assert_series_equal(-self.series, -1 * self.series) | ||
|
||
|
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