Skip to content

Commit

Permalink
fix failing import in pandas<2.2.2 (#1410)
Browse files Browse the repository at this point in the history
Co-authored-by: samuel.oranyeli <[email protected]>
  • Loading branch information
samukweku and samuel.oranyeli authored Sep 28, 2024
1 parent 7e6dfb3 commit 0b20cc6
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions janitor/functions/conditional_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
is_timedelta64_dtype,
)
from pandas.core.dtypes.concat import concat_compat
from pandas.core.dtypes.missing import (
construct_1d_array_from_inferred_fill_value,
)
from pandas.core.reshape.merge import _MergeOperation

from janitor.functions.utils import (
Expand Down Expand Up @@ -1513,3 +1510,20 @@ def get_join_indices(
return_matching_indices=True,
return_ragged_arrays=return_ragged_arrays,
)


# copied from pandas/core/dtypes/missing.py
# seems function was introduced in 2.2.2
# we should support lesser versions - at least 2.0.0
def construct_1d_array_from_inferred_fill_value(
value: object, length: int
) -> np.ndarray:
# Find our empty_value dtype by constructing an array
# from our value and doing a .take on it
from pandas.core.algorithms import take_nd
from pandas.core.construction import sanitize_array
from pandas.core.indexes.base import Index

arr = sanitize_array(value, Index(range(1)), copy=False)
taker = -1 * np.ones(length, dtype=np.intp)
return take_nd(arr, taker)

0 comments on commit 0b20cc6

Please sign in to comment.