Skip to content

BUG: Allow all int types for merge (GH28870) #28875

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 8 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.25.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Groupby/resample/rolling
Reshaping
^^^^^^^^^

-
- Fix to ensure all int dtypes can be used in :func:`merge_asof` when using a tolerance value. Before every non-int64 type would raise an erroneous ``MergeError`` (:issue:`28870`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to 1.0

Before -> Previously

-
-
-
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
is_dtype_equal,
is_extension_array_dtype,
is_float_dtype,
is_int64_dtype,
is_integer,
is_integer_dtype,
is_list_like,
Expand Down Expand Up @@ -1641,7 +1640,7 @@ def _get_merge_keys(self):
if self.tolerance < Timedelta(0):
raise MergeError("tolerance must be positive")

elif is_int64_dtype(lt):
elif is_integer_dtype(lt):
if not is_integer(self.tolerance):
raise MergeError(msg)
if self.tolerance < 0:
Expand Down
20 changes: 20 additions & 0 deletions pandas/tests/reshape/merge/test_merge_asof.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,3 +1287,23 @@ def test_timedelta_tolerance_nearest(self):
)

assert_frame_equal(result, expected)

@pytest.mark.parametrize(
"dtype",
[int, "int64", "int32", "int16", "int8", "uint64", "uint32", "uint16", "uint8"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the any_int_dtype fixture instead

)
def test_int_type_tolerance(self, dtype):
# GH #28870

left = pd.DataFrame({"a": [0, 10, 20], "left_val": [1, 2, 3]})
right = pd.DataFrame({"a": [5, 15, 25], "right_val": [1, 2, 3]})
left["a"] = left["a"].astype(dtype)
right["a"] = right["a"].astype(dtype)

expected = pd.DataFrame(
{"a": [0, 10, 20], "left_val": [1, 2, 3], "right_val": [np.nan, 1.0, 2.0]}
)
expected["a"] = expected["a"].astype(dtype)

result = pd.merge_asof(left, right, on="a", tolerance=10)
assert_frame_equal(result, expected)