Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
merge_asof fails when using left_index/right_index with a tolerance parameter #15135
Comments
|
If you patch pandas/tools/merge.py at around line 1131 with something like if self.tolerance is not None:
if self.left_index:
lt = self.left.index
else:
lt = left_join_keys[-1]Then the expected result is obtained (i.e. the merge is successful). Happy to turn this into a PR if you agree it's the way to go. |
|
hmm, that does look buggy. cc @chrisaycock |
jreback
added Bug Difficulty Intermediate Effort Low Reshaping
labels
Jan 15, 2017
jreback
added this to the
0.20.0
milestone
Jan 15, 2017
|
FYI these are documented in 0.19.2, when they were added ( |
|
Hmm,
and later:
I don't see a terminating I can look into this later today to see if the fix is required there, though I would want to run a bunch of regression tests. By the way, if I set the index in just one DataFrame, then it works, leading evidence to my above hypothesis:
and
Good catch, @ajcr. |
chrisaycock
referenced
this issue
Jan 16, 2017
Closed
BUG: Allow tolerance when left_index/right_index enabled for merge_asof() (#15135) #15139
|
My proposal turned-out to be pretty difficult because of the integrated |
jreback
closed this
in 4fe91e2
Jan 17, 2017
AnkurDedania
added a commit
to AnkurDedania/pandas
that referenced
this issue
Mar 21, 2017
|
|
+ AnkurDedania |
1a835ef
|
ajcr commentedJan 15, 2017
•
edited
Problem description
Using the DataFrames trades and quotes from the
merge_asofdocumentation as an example, there's an issue when usingmerge_asofto merge on indexes usingleft_index/right_index(rather than column names) and additionally specifying a tolerance parameter.Admittedly, the
left_index/right_indexparameters are not documented for this function (in the prototype description), but they are still valid parameters (and have an example in the docs). It could be seen as inconsistent that they sometimes work as expected and sometimes raise a cryptic error message.For example, first set the 'time' column of each DataFrame as the index:
Then
pd.merge_asof(trades, quotes, left_index=True, right_index=True, by='ticker')works exactly aspd.asof_merge(trades, quotes, on='time', by='ticker')(as expected).However,
pd.merge_asof(trades, quotes, left_index=True, right_index=True, by='ticker', tolerance=pd.Timedelta('2ms'))(specifying a tolerance) raises an error:I would have expected it work exactly as
pd.merge_asof(trades, quotes, on='time', by='ticker', tolerance=pd.Timedelta('2ms'))works. Failing this, an error telling me that I cannot use a tolerance when merging on indexes would be welcome.Output of
pd.show_versions()INSTALLED VERSIONS
commit: None
python: 3.4.4.final.0
python-bits: 64
OS: Linux
OS-release: 3.16.0-4-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8
pandas: 0.19.2
nose: 1.3.4
pip: 9.0.1
setuptools: 31.0.1.post20161215
Cython: 0.23.4
numpy: 1.11.3
scipy: 0.18.1
statsmodels: 0.6.1
xarray: 0.7.2
IPython: 5.1.0
sphinx: 1.2.3
patsy: 0.4.1
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: 3.1.1
numexpr: 2.6.1
matplotlib: 1.5.1
openpyxl: 1.8.5
xlrd: 0.9.3
xlwt: None
xlsxwriter: 0.6.7
lxml: 3.6.4
bs4: 4.3.2
html5lib: 0.99999
httplib2: None
apiclient: None
sqlalchemy: 0.9.9
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.36.0
pandas_datareader: None