Skip to content

BUG: Raise ValueError for non numerical join columns in merge_asof #34488

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

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
660d2f5
Raise ValueError for non numerical join columns in merge_asof
phofl May 30, 2020
cafedcc
Delete unused imports
phofl May 30, 2020
fa1d909
Implement review requests
phofl May 30, 2020
34a5633
Run black pandas
phofl May 30, 2020
783bc60
Change error message
phofl May 31, 2020
e086864
Change whats new entry
phofl May 31, 2020
a4001c6
Merge branch 'master' of https://github.com/pandas-dev/pandas into 29130
phofl May 31, 2020
aaa3480
Change error type
phofl May 31, 2020
ec3147e
Move dtype check
phofl May 31, 2020
129eb77
Use raw string
phofl May 31, 2020
4680833
Move check again
phofl Jun 1, 2020
fb55c9f
Move dtype check to _get_merge_keys
phofl Jun 1, 2020
72fb8b4
Run black pandas
phofl Jun 1, 2020
0103974
Overwrite _maybe_coerce_merge_keys
phofl Jun 1, 2020
4cc8bdc
Merge branch 'master' of https://github.com/pandas-dev/pandas into 29130
phofl Jun 3, 2020
a6048a6
Merge branch 'master' of https://github.com/pandas-dev/pandas into 29130
phofl Sep 16, 2020
cdaa8ef
Move whats new entry
phofl Sep 16, 2020
47e211c
Add docs from other pr
phofl Sep 23, 2020
3129353
Merge branch 'master' of https://github.com/pandas-dev/pandas into 29130
phofl Sep 23, 2020
0242f47
Run black pandas
phofl Sep 23, 2020
ef47721
Revert "Add docs from other pr"
phofl Sep 23, 2020
109c824
Merge branch 'master' of https://github.com/pandas-dev/pandas into 29130
phofl Dec 29, 2020
3a66f05
Move whatsnew
phofl Dec 29, 2020
da377c7
Merge branch 'master' of https://github.com/pandas-dev/pandas into 29130
phofl Jan 1, 2021
c0ce857
Move merge asof validation
phofl Jan 4, 2021
2c164c5
Remove newline
phofl Jan 4, 2021
a00eb9c
Parametrize test further
phofl Jan 4, 2021
f62a873
Merge branch 'master' of https://github.com/pandas-dev/pandas into 29130
phofl Jan 4, 2021
4782233
Add comment
phofl Jan 4, 2021
6ebb7a3
Change Error
phofl Jan 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ Reshaping
- Bug in :meth:`DataFrame.replace` casts columns to ``object`` dtype if items in ``to_replace`` not in values (:issue:`32988`)
- Ensure only named functions can be used in :func:`eval()` (:issue:`32460`)
- Fixed bug in :func:`melt` where melting MultiIndex columns with ``col_level`` > 0 would raise a ``KeyError`` on ``id_vars`` (:issue:`34129`)
- :meth:`merge_asof` raises ``ValueError`` instead of cryptic ``TypeError`` in case of non numerical merge columns (:issue:`29130`)

Sparse
^^^^^^
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,9 @@ def flip(xs) -> np.ndarray:
)
tolerance = self.tolerance

if is_object_dtype(right_values.dtype) or is_object_dtype(left_values.dtype):
raise TypeError("Both inputs have to be from numeric dtype")

# we require sortedness and non-null values in the join keys
if not Index(left_values).is_monotonic:
side = "left"
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/reshape/merge/test_merge_asof.py
Original file line number Diff line number Diff line change
Expand Up @@ -1339,3 +1339,15 @@ def test_merge_index_column_tz(self):
index=pd.Index([0, 1, 2, 3, 4]),
)
tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize(
"data",
[["2019-06-01 00:09:12", "2019-06-01 00:10:29"], [1.0, "2019-06-01 00:10:29"]],
)
def test_non_numerical_dtype(data):
# GH 29130
left = pd.DataFrame({"x": data})
right = pd.DataFrame({"x": data})
with pytest.raises(TypeError, match="Both inputs have to be from numeric dtype"):
pd.merge_asof(left, right, on="x")