-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix concat key name #14292
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
BUG: Fix concat key name #14292
Conversation
'bar': [0.1, 0.2, 0.3, 0.4]}) | ||
index = Index(['a', 'b'], name='baz') | ||
concatted = pd.concat([df, df], keys=index) | ||
assert_equal(concatted.index.names, FrozenList(['baz', None])) |
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.
always use assert_frame_equal and construct and expected frame
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 sure that assert_frame_equal
checks for names of indices here.
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.
sure it does
see doc string
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 see -- fixed now. Also added a couple extra test cases.
if names is None and hasattr(keys, 'names'): | ||
self.names = keys.names | ||
else: | ||
self.names = names |
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.
names or getattr(keys, 'names', None)
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.
fixed
Current coverage is 85.25% (diff: 100%)@@ master #14292 diff @@
==========================================
Files 140 140
Lines 50632 50634 +2
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
- Hits 43171 43170 -1
- Misses 7461 7464 +3
Partials 0 0
|
clean_objs.append(v) | ||
objs = clean_objs | ||
keys = clean_keys | ||
clean_keys_index = Index(clean_keys_list) |
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.
use _ensure_index
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.
Fixed.
clean_objs.append(v) | ||
objs = clean_objs | ||
keys = clean_keys | ||
clean_keys_index = Index(clean_keys_list) | ||
if isinstance(keys, Index): |
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.
this logic seems convoluted, can you simplify?
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.
Seems like you should be able to change the name of clean_keys_list
back to clean_keys
and
if isinstance(keys, Index):
keys = Index(clean_keys, name=keys.name)
(untested)
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.
Fixed.
05217c8
to
40325a9
Compare
@jreback I think all comments are addressed now. |
Fixes a bug where `pd.concat` didn't propagate the names of keys used to create a hierarchical index.
da560b0
to
44932cc
Compare
@jreback Changed whatsnew entry to 0.19.1. Is there anything left to do before merging? |
@@ -1369,7 +1369,9 @@ def __init__(self, objs, axis=0, join='outer', join_axes=None, | |||
clean_keys.append(k) | |||
clean_objs.append(v) | |||
objs = clean_objs | |||
keys = clean_keys | |||
name = getattr(keys, 'name', None) | |||
keys = _ensure_index(Index(clean_keys)) |
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.
hmm I don't think you need the _ensure_index
if you are forcing the index
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.
yes appears that is correct: cdc76f6 looks fine.
thanks @bkandel |
* commit 'v0.19.0-14-ga40e185': (37 commits) BUG: Bug in localizing an ambiguous timezone when a boolean is passed Convert readthedocs links for their .org -> .io migration for hosted projects (pandas-dev#14406) DOC: formatting in basics.rst BLD/CI: cython cache pxd files (pandas-dev#14363) BUG: set_levels set illegal levels. (pandas-dev#14236) DOC: add whitespace to v0.19.1 bug fix section change impl details slightly for pandas-dev#14292 BUG: Fix concat key name DOC: add 0.19.1 whatsnew file (pandas-dev#14366) DOC: to_csv warns regarding quoting behaviour for floats pandas-dev#14195 (pandas-dev#14228) DOC: fix formatting issue with msgpack table TST: pandas-dev#14345 fixes TestDatetimeIndexOps test_nat AssertionErrors on 32-bit docs: Remove old warning from dsintro.rst (pandas-dev#14365) DOC: minor v0.19.0 whatsnew corrections RLS: v0.19.0 DOC: update release notes DOC: Latest fixes for whatsnew file to_latex encoding follows the documentation (py2 ascii, py3 utf8) (pandas-dev#14329) DOC: fix some sphinx build issues (pandas-dev#14332) TST: fix period tests for numpy 1.9.3 (GH14183) (pandas-dev#14331) ...
closes pandas-dev#14252 Fixes a bug where `pd.concat` didn't propagate the names of keys used to create a hierarchical index. Author: Ben Kandel <[email protected]> Closes pandas-dev#14292 from bkandel/fix_concat_key_name and squashes the following commits: cdc76f6 [Ben Kandel] take out _ensure_index 4a301f8 [Ben Kandel] put back in Index coercion d8e2c17 [Ben Kandel] remove coercion to Index before _ensure_index 44932cc [Ben Kandel] changed whatsnew entry to 0.19.1 c51df19 [Ben Kandel] _ensure_index b54b081 [Ben Kandel] simplified logic 3256119 [Ben Kandel] typo 789ecd4 [Ben Kandel] use _ensure_index 350e724 [Ben Kandel] simplified logic 9615a69 [Ben Kandel] extra tests 5c0108b [Ben Kandel] comments dd3c4cc [Ben Kandel] comments 5cd8392 [Ben Kandel] added test for names bc5f1fb [Ben Kandel] cleanup ef6db68 [Ben Kandel] BUG: Propagate key names in concat.
git diff upstream/master | flake8 --diff
Fixes a bug where
pd.concat
didn't propagate the names of keys used to createa hierarchical index.