-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
BUG: Load data from a CategoricalIndex for dtype comparison, closes #… #16738
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
b878886
6f19f21
257edec
081c3ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…d ordered CategoricalIndex test
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import numpy as np | ||
from pandas import Index | ||
from pandas import Index, DataFrame, Categorical, merge | ||
|
||
from pandas._libs import join as _join | ||
import pandas.util.testing as tm | ||
from pandas.util.testing import assert_almost_equal | ||
from pandas.util.testing import assert_almost_equal, assert_frame_equal | ||
|
||
|
||
class TestIndexer(object): | ||
|
@@ -196,20 +196,38 @@ def test_inner_join_indexer2(): | |
|
||
def test_merge_join_categorical_multiindex(): | ||
# From issue 16627 | ||
import pandas as pd | ||
a = {'Cat1': pd.Categorical(['a', 'b', 'a', 'c', 'a', 'b'], | ||
['a', 'b', 'c']), | ||
a = {'Cat1': Categorical(['a', 'b', 'a', 'c', 'a', 'b'], | ||
['a', 'b', 'c']), | ||
'Int1': [0, 1, 0, 1, 0, 0]} | ||
a = pd.DataFrame(a) | ||
a = DataFrame(a) | ||
|
||
b = {'Cat': pd.Categorical(['a', 'b', 'c', 'a', 'b', 'c'], | ||
['a', 'b', 'c']), | ||
b = {'Cat': Categorical(['a', 'b', 'c', 'a', 'b', 'c'], | ||
['a', 'b', 'c']), | ||
'Int': [0, 0, 0, 1, 1, 1], | ||
'Factor': [1.1, 1.2, 1.3, 1.4, 1.5, 1.6]} | ||
b = pd.DataFrame(b).set_index(['Cat', 'Int'])['Factor'] | ||
b = DataFrame(b).set_index(['Cat', 'Int'])['Factor'] | ||
|
||
c = pd.merge(a, b.reset_index(), left_on=['Cat1', 'Int1'], | ||
right_on=['Cat', 'Int'], how='left') | ||
c = merge(a, b.reset_index(), left_on=['Cat1', 'Int1'], | ||
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 |
||
right_on=['Cat', 'Int'], how='left') | ||
d = a.join(b, on=['Cat1', 'Int1']) | ||
c = c.drop(['Cat', 'Int'], axis=1) | ||
assert_almost_equal(c, d) | ||
assert_frame_equal(c, d) | ||
|
||
a = {'Cat1': Categorical(['a', 'b', 'a', 'c', 'a', 'b'], | ||
['b', 'a', 'c'], | ||
ordered=True), | ||
'Int1': [0, 1, 0, 1, 0, 0]} | ||
a = DataFrame(a) | ||
|
||
b = {'Cat': Categorical(['a', 'b', 'c', 'a', 'b', 'c'], | ||
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. how is this second example different that the first? its not immediately obvious and needs a comment (or is it a dupe) 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. It is an ordered categorical. Wrote a comment. |
||
['b', 'a', 'c'], | ||
ordered=True), | ||
'Int': [0, 0, 0, 1, 1, 1], | ||
'Factor': [1.1, 1.2, 1.3, 1.4, 1.5, 1.6]} | ||
b = DataFrame(b).set_index(['Cat', 'Int'])['Factor'] | ||
|
||
c = merge(a, b.reset_index(), left_on=['Cat1', 'Int1'], | < 41B8 /tr>||
right_on=['Cat', 'Int'], how='left') | ||
d = a.join(b, on=['Cat1', 'Int1']) | ||
c = c.drop(['Cat', 'Int'], axis=1) | ||
assert_frame_equal(c, d) |
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.
Bug in joining on a
MultiIndex
with acategory
dtype for a levelThere 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.
Done. I also moved this to the Reshaping category.