Skip to content

Commit eaba844

Browse files
committed
import code into isin() and remove function
1 parent 670a8f9 commit eaba844

File tree

7 files changed

+20
-87
lines changed

7 files changed

+20
-87
lines changed

doc/source/reference/arrays.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ Data type introspection
667667
api.types.is_dtype_equal
668668
api.types.is_extension_array_dtype
669669
api.types.is_float_dtype
670-
api.types.is_implicit_conversion_to_float64
671670
api.types.is_int64_dtype
672671
api.types.is_integer_dtype
673672
api.types.is_interval_dtype

doc/source/whatsnew/v3.0.0.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ Other API changes
404404
- Index set operations (like union or intersection) will now ignore the dtype of
405405
an empty ``RangeIndex`` or empty ``Index`` with object dtype when determining
406406
the dtype of the resulting Index (:issue:`60797`)
407-
- Added :func:`pandas.api.types.is_implicit_conversion_to_float64` to check if there is a silent conversion to float64 between two dtypes(:issue:`61676`)
408407

409408
.. ---------------------------------------------------------------------------
410409
.. _whatsnew_300.deprecations:

pandas/core/algorithms.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
is_extension_array_dtype,
5151
is_float,
5252
is_float_dtype,
53-
is_implicit_conversion_to_float64,
5453
is_integer,
5554
is_integer_dtype,
5655
is_list_like,
@@ -507,11 +506,26 @@ def isin(comps: ListLike, values: ListLike) -> npt.NDArray[np.bool_]:
507506
orig_values = list(values)
508507
values = _ensure_arraylike(orig_values, func_name="isin-targets")
509508

510-
if (
511-
len(values) > 0
512-
and values.dtype.kind in "iufcb"
513-
and is_implicit_conversion_to_float64(values, comps)
514-
):
509+
try:
510+
src = comps.dtype
511+
tar = values.dtype
512+
# check only valid dtypes related to implicit conversion to float64
513+
# other data types derived from 64-bit integers such as U/Int64Dtype
514+
# should also work
515+
if (
516+
src.kind in "iu"
517+
and src.itemsize == 8 # type: ignore[union-attr]
518+
and tar.kind in "iu"
519+
and tar.itemsize == 8 # type: ignore[union-attr]
520+
):
521+
is_implicit_conversion_to_float64 = src != tar
522+
else:
523+
is_implicit_conversion_to_float64 = False
524+
except (TypeError, AttributeError, ImportError):
525+
# invalid comparison
526+
is_implicit_conversion_to_float64 = False
527+
528+
if (is_implicit_conversion_to_float64):
515529
# GH#46485 Use object to avoid upcast to float64 later
516530
# TODO: Share with _find_common_type_compat
517531
values = construct_1d_object_array_from_listlike(orig_values)

pandas/core/dtypes/api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
is_float,
1818
is_float_dtype,
1919
is_hashable,
20-
is_implicit_conversion_to_float64,
2120
is_int64_dtype,
2221
is_integer,
2322
is_integer_dtype,
@@ -60,7 +59,6 @@
6059
"is_float",
6160
"is_float_dtype",
6261
"is_hashable",
63-
"is_implicit_conversion_to_float64",
6462
"is_int64_dtype",
6563
"is_integer",
6664
"is_integer_dtype",

pandas/core/dtypes/common.py

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -713,80 +713,6 @@ def is_dtype_equal(source, target) -> bool:
713713
return False
714714

715715

716-
def is_implicit_conversion_to_float64(source, target) -> bool:
717-
"""
718-
Check if there is an implicit conversion to float64 with both dtypes.
719-
720-
Parameters
721-
----------
722-
source : type or str
723-
The first dtype to compare.
724-
target : type or str
725-
The second dtype to compare.
726-
727-
Returns
728-
-------
729-
boolean
730-
Whether or not there is an implicit conversion to float64.
731-
732-
See Also
733-
--------
734-
api.types.is_categorical_dtype : Check whether the provided array or dtype
735-
is of the Categorical dtype.
736-
api.types.is_string_dtype : Check whether the provided array or dtype
737-
is of the string dtype.
738-
api.types.is_object_dtype : Check whether an array-like or dtype is of the
739-
object dtype.
740-
741-
Examples
742-
--------
743-
>>> from pandas.api.types import is_implicit_conversion_to_float64
744-
>>> is_implicit_conversion_to_float64(int, float)
745-
False
746-
>>> is_implicit_conversion_to_float64("int", int)
747-
False
748-
>>> is_implicit_conversion_to_float64(int, np.int64)
749-
False
750-
>>> is_implicit_conversion_to_float64(np.uint64, np.int64)
751-
True
752-
>>> is_implicit_conversion_to_float64(np.uint64, np.float64)
753-
False
754-
>>> is_implicit_conversion_to_float64(np.uint64, np.uint64)
755-
False
756-
>>> is_implicit_conversion_to_float64(np.uint32, np.uint32)
757-
False
758-
>>> is_implicit_conversion_to_float64(np.uint32, np.int32)
759-
False
760-
>>> is_implicit_conversion_to_float64(np.int32, np.int32)
761-
False
762-
>>> is_implicit_conversion_to_float64(object, "category")
763-
False
764-
>>> is_implicit_conversion_to_float64(np.int64, pd.UInt64Dtype())
765-
True
766-
>>> from pandas.core.dtypes.dtypes import CategoricalDtype
767-
>>> is_implicit_conversion_to_float64(CategoricalDtype(), "category")
768-
False
769-
"""
770-
try:
771-
src = _get_dtype(source)
772-
tar = _get_dtype(target)
773-
# check only valid dtypes related to implicit conversion to float64
774-
# other data types derived from 64-bit integers such as U/Int64Dtype
775-
# should also work
776-
if (
777-
src.kind in "iu"
778-
and src.itemsize == 8 # type: ignore[union-attr]
779-
and tar.kind in "iu"
780-
and tar.itemsize == 8 # type: ignore[union-attr]
781-
):
782-
return src != tar
783-
else:
784-
return False
785-
except (TypeError, AttributeError, ImportError):
786-
# invalid comparison
787-
return False
788-
789-
790716
def is_integer_dtype(arr_or_dtype) -> bool:
791717
"""
792718
Check whether the provided array or dtype is of an integer dtype.
@@ -2008,7 +1934,6 @@ def is_all_strings(value: ArrayLike) -> bool:
20081934
"is_extension_array_dtype",
20091935
"is_file_like",
20101936
"is_float_dtype",
2011-
"is_implicit_conversion_to_float64",
20121937
"is_int64_dtype",
20131938
"is_integer_dtype",
20141939
"is_interval_dtype",

pandas/tests/api/test_api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ class TestApi(Base):
295295
"is_float",
296296
"is_float_dtype",
297297
"is_hashable",
298-
"is_implicit_conversion_to_float64",
299298
"is_int64_dtype",
300299
"is_integer",
301300
"is_integer_dtype",

pandas/tests/api/test_types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class TestTypes(Base):
2020
"is_dtype_equal",
2121
"is_float",
2222
"is_float_dtype",
23-
"is_implicit_conversion_to_float64",
2423
"is_int64_dtype",
2524
"is_integer",
2625
"is_integer_dtype",

0 commit comments

Comments
 (0)