Skip to content

Commit 112fd0b

Browse files
Fixes pandas-dev#55884- Added else for invalid fill_method (pandas-dev#55927)
* Fixes pandas-dev#55884- Added else for invalid fill_method * Fixes pandas-dev#55884- Added else for invalid fill_method * Update pandas/tests/reshape/merge/test_merge_ordered.py Co-authored-by: Matthew Roeschke <[email protected]> * Update pandas/tests/reshape/merge/test_merge_ordered.py Co-authored-by: Matthew Roeschke <[email protected]> * Update pandas/core/reshape/merge.py Co-authored-by: Matthew Roeschke <[email protected]> * Fixed mergeordered ValueError Message * Use pytest fixtures & parametrize for tests --------- Co-authored-by: Matthew Roeschke <[email protected]>
1 parent c4f0e6f commit 112fd0b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pandas/core/reshape/merge.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1863,9 +1863,11 @@ def get_result(self, copy: bool | None = True) -> DataFrame:
18631863
right_indexer = cast("npt.NDArray[np.intp]", right_indexer)
18641864
left_join_indexer = libjoin.ffill_indexer(left_indexer)
18651865
right_join_indexer = libjoin.ffill_indexer(right_indexer)
1866-
else:
1866+
elif self.fill_method is None:
18671867
left_join_indexer = left_indexer
18681868
right_join_indexer = right_indexer
1869+
else:
1870+
raise ValueError("fill_method must be 'ffill' or None")
18691871

18701872
result = self._reindex_and_concat(
18711873
join_index, left_join_indexer, right_join_indexer, copy=copy

pandas/tests/reshape/merge/test_merge_ordered.py

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
import numpy as np
24
import pytest
35

@@ -209,3 +211,11 @@ def test_elements_not_in_by_but_in_df(self):
209211
msg = r"\{'h'\} not found in left columns"
210212
with pytest.raises(KeyError, match=msg):
211213
merge_ordered(left, right, on="E", left_by=["G", "h"])
214+
215+
@pytest.mark.parametrize("invalid_method", ["linear", "carrot"])
216+
def test_ffill_validate_fill_method(self, left, right, invalid_method):
217+
# GH 55884
218+
with pytest.raises(
219+
ValueError, match=re.escape("fill_method must be 'ffill' or None")
220+
):
221+
merge_ordered(left, right, on="key", fill_method=invalid_method)

0 commit comments

Comments
 (0)