-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUGfix: reset_index can reset index name (#17067) #17243
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 1 commit
e0516e9
2d0e937
f4d1ece
e49d6c3
5759763
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 |
---|---|---|
|
@@ -206,7 +206,7 @@ def is_bool_indexer(key): | |
|
||
def _default_index(n): | ||
from pandas.core.index import RangeIndex | ||
return RangeIndex(0, n, name=None) | ||
return RangeIndex(0, n, name='index') | ||
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 don't think this is right... the name of a default index should just be None. |
||
|
||
|
||
def _mut_exclusive(**kwargs): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2110,7 +2110,7 @@ def argsort(self, *args, **kwargs): | |
return result.argsort(*args, **kwargs) | ||
|
||
def __add__(self, other): | ||
return Index(np.array(self) + other) | ||
return Index(np.array(self) + other, name=self.name) | ||
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. actually this is not correct. We don't assign the index name on a boolean operation. only on an inplace operation (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. @jreback Thank you for your advice on my first pandas PR. :) Should I raise exception in case of
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. no, this is slightly complicated. the |
||
|
||
def __radd__(self, other): | ||
return Index(other + np.array(self)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -859,6 +859,17 @@ def test_iadd_string(self): | |
index += '_x' | ||
assert 'a_x' in index | ||
|
||
def test_iadd_index_name(self): | ||
s = pd.Series([1, 2, 3]) | ||
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 issue number as a comment. add a 1-liner here what you are testing |
||
s.index.name = 'foo' | ||
|
||
s.index += 1 | ||
assert s.index.name == 'foo' | ||
|
||
def test_reset_index_name(self): | ||
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 test needs to go to pandas/tests/frame/test_alter_axes.py (with other reset_index tests) |
||
df = pd.DataFrame(index=pd.Index([], name='x')) | ||
assert df.reset_index(level=[]).index.name is 'index' | ||
|
||
def test_difference(self): | ||
|
||
first = self.strIndex[5:20] | ||
|
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.
be more descriptive here, no space before the issue number and the colon