|
5 | 5 | import pandas as pd
|
6 | 6 | import pandas_flavor as pf
|
7 | 7 | from pandas.core.dtypes.common import (
|
8 |
| - is_categorical_dtype, |
9 | 8 | is_datetime64_dtype,
|
10 | 9 | is_dtype_equal,
|
11 | 10 | is_extension_array_dtype,
|
@@ -336,29 +335,27 @@ def _conditional_join_type_check(
|
336 | 335 | "when use_numba is set to True"
|
337 | 336 | )
|
338 | 337 |
|
339 |
| - permitted_types = { |
340 |
| - is_datetime64_dtype, |
341 |
| - is_numeric_dtype, |
342 |
| - is_string_dtype, |
343 |
| - } |
344 |
| - for func in permitted_types: |
345 |
| - # change is based on this PR |
346 |
| - # https://github.com/pandas-dev/pandas/pull/52527/files |
347 |
| - if isinstance(left_column.dtype, pd.CategoricalDtype) or func( |
348 |
| - left_column |
349 |
| - ): |
350 |
| - break |
351 |
| - else: |
352 |
| - raise TypeError( |
353 |
| - "conditional_join only supports " |
354 |
| - "string, category, numeric, or date dtypes (without timezone) - " |
355 |
| - f"'{left_column.name} is of type {left_column.dtype}." |
356 |
| - ) |
| 338 | + is_categorical_dtype = isinstance(left_column.dtype, pd.CategoricalDtype) |
357 | 339 |
|
358 |
| - lk_is_cat = is_categorical_dtype(left_column) |
359 |
| - rk_is_cat = is_categorical_dtype(right_column) |
| 340 | + if not is_categorical_dtype: |
| 341 | + permitted_types = { |
| 342 | + is_datetime64_dtype, |
| 343 | + is_numeric_dtype, |
| 344 | + is_string_dtype, |
| 345 | + } |
| 346 | + for func in permitted_types: |
| 347 | + if func(left_column.dtype): |
| 348 | + break |
| 349 | + else: |
| 350 | + raise TypeError( |
| 351 | + "conditional_join only supports " |
| 352 | + "string, category, numeric, or " |
| 353 | + "date dtypes (without timezone) - " |
| 354 | + f"'{left_column.name} is of type " |
| 355 | + f"{left_column.dtype}." |
| 356 | + ) |
360 | 357 |
|
361 |
| - if lk_is_cat & rk_is_cat: |
| 358 | + if is_categorical_dtype: |
362 | 359 | if not left_column.array._categories_match_up_to_permutation(
|
363 | 360 | right_column.array
|
364 | 361 | ):
|
|
0 commit comments