Skip to content

Unary plus feature #16103

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
wants to merge 2 commits into from
Closed

Unary plus feature #16103

wants to merge 2 commits into from

Conversation

wuisawesome
Copy link

Copy link
Member

@shoyer shoyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One additional concern: unary + should only be defined defined for numeric types that can represent signed quantities (including timedelta). For datetime and strings, it should raise TypeError.

Finally, note that implementing this is a little more complicated that writing +_values_from_object(self), because unfortunately numpy does not implement unary + correctly, either (numpy/numpy#8967).

@@ -838,8 +838,7 @@ def _set_axis_name(self, name, axis=0):
1 2
2 3
>>> df.index = pd.MultiIndex.from_product([['A'], ['a', 'b', 'c']])
>>> df._set_axis_name(["bar", "baz"])
A
>>> df._set_axis_name(["bar", "baz"]) A
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be changed

@@ -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, self.series)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to add a test for dataframes, too

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm new to contributing to this Pandas. Are there any other datatypes that I need to write test cases for other than series and dataframes?

I'll write these tests and resubmit tomorrow.

@wuisawesome
Copy link
Author

Thanks for the feedback! I made a lot of embarrassing small mistakes in this pull request that I'll fix and resubmit.

Regarding the concern about which values the + operator should be defined for, why not simply define it for the widest range of values possible. It should be the responsibility of the user to ensure that their operator works correctly. This is consistent with the current implementation of __neg__.

Ideally np.array will be fixed and this entire point will be moot.

@jorisvandenbossche
Copy link
Member

I'll fix and resubmit.

Just in case you don't know, for resubmitting, you just have to push to the same branch and this PR will be updated (no need to submit a new PR)

@wuisawesome
Copy link
Author

no need to submit a new PR

That's a bit of an issue. I was messing around and really broke that branch so I made a new one.

I will definitely keep that in mind in the future and for now I'll link to the new branch in this thread when I submit the new PR. Hopefully it won't be too confusing if anyone looks in this thread later

@jorisvandenbossche
Copy link
Member

jorisvandenbossche commented Apr 24, 2017

You can rename your branch locally to the original name, that will work as well to update this PR

@wuisawesome
Copy link
Author

I attempted to rename the branch but something went wrong. The new PR is here: #16106

Sorry for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unary plus missing for Series and DataFrame
3 participants