-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: merge_asof raises when grouping on multiple columns with a categorical #16454
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
Labels
Comments
cc @chrisaycock should this be supported? If not we can raise a better error message. |
this could work, but is not implemented atm because of how the multiple grouping is done. |
I also ran into this: import pandas as pd
def convert_to_cat(df):
return df.assign(cat1=pd.Categorical(df.cat1),
cat2=pd.Categorical(df.cat2))
left = pd.DataFrame({'time': [1, 2, 3, 6, 7],
'cat1': ['a', 'a', 'b', 'b', 'b'],
'cat2': ['x', 'y', 'x', 'y', 'x'],
'left': [0, 1, 2, 3, 4]})
right = pd.DataFrame({'time': [1, 5, 10],
'cat1': ['a', 'b', 'b'],
'cat2': ['x', 'y', 'x'],
'right': [0, 1, 2]})
left_cat = convert_to_cat(left)
right_cat = convert_to_cat(right)
# This works: multiple by= columns, with object dtype.
result = pd.merge_asof(left, right, on='time', by=['cat1', 'cat2'])
# This also works: one by= column, with category dtype.
result_1cat = pd.merge_asof(left_cat, right_cat, on='time', by='cat1')
# This raises SystemError: multiple by= columns, with category dtype.
result_2cats = pd.merge_asof(left_cat, right_cat, on='time', by=['cat1', 'cat2']) Here is the backtrace produced by the last line, if that helps:
This is on Pandas 0.24.2. |
5 tasks
This looks to work on master. Could use a regression test.
|
dwhu
added a commit
to dwhu/pandas
that referenced
this issue
Jan 3, 2020
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code Sample, a copy-pastable example if possible
Problem description
merge_asof
takes aby
argument which defines the groups to merge between. Whenby
is any single column, or multiple non-categorical columns, the merge succeeds. Whenby
includes multiple columns, at least one of which is categorical, an error is raised.Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.10.10-100.fc24.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: C
LANG: C
LOCALE: None.None
pandas: 0.20.1
pytest: None
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.19.0
xarray: None
IPython: 4.2.1
sphinx: None
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: 1.2.0
tables: None
numexpr: 2.6.2
feather: None
matplotlib: 2.0.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: