Skip to content

Commit c50b0e7

Browse files
jbrockmendeljreback
authored andcommitted
CLN: Trim unused/unnecessary code (#27440)
1 parent 1857bff commit c50b0e7

File tree

4 files changed

+1
-126
lines changed

4 files changed

+1
-126
lines changed

pandas/core/dtypes/cast.py

-12
Original file line numberDiff line numberDiff line change
@@ -571,18 +571,6 @@ def maybe_upcast(values, fill_value=np.nan, dtype=None, copy=False):
571571
return values, fill_value
572572

573573

574-
def maybe_cast_item(obj, item, dtype):
575-
chunk = obj[item]
576-
577-
if chunk.values.dtype != dtype:
578-
if dtype in (np.object_, np.bool_):
579-
obj[item] = chunk.astype(np.object_)
580-
elif not issubclass(dtype, (np.integer, np.bool_)): # pragma: no cover
581-
raise ValueError(
582-
"Unexpected dtype encountered: {dtype}".format(dtype=dtype)
583-
)
584-
585-
586574
def invalidate_string_dtypes(dtype_set):
587575
"""Change string like dtypes to object for
588576
``DataFrame.select_dtypes()``.

pandas/core/dtypes/common.py

-89
Original file line numberDiff line numberDiff line change
@@ -898,41 +898,6 @@ def is_dtype_equal(source, target):
898898
return False
899899

900900

901-
def is_dtype_union_equal(source, target):
902-
"""
903-
Check whether two arrays have compatible dtypes to do a union.
904-
numpy types are checked with ``is_dtype_equal``. Extension types are
905-
checked separately.
906-
907-
Parameters
908-
----------
909-
source : The first dtype to compare
910-
target : The second dtype to compare
911-
912-
Returns
913-
-------
914-
boolean
915-
Whether or not the two dtypes are equal.
916-
917-
>>> is_dtype_equal("int", int)
918-
True
919-
920-
>>> is_dtype_equal(CategoricalDtype(['a', 'b'],
921-
... CategoricalDtype(['b', 'c']))
922-
True
923-
924-
>>> is_dtype_equal(CategoricalDtype(['a', 'b'],
925-
... CategoricalDtype(['b', 'c'], ordered=True))
926-
False
927-
"""
928-
source = _get_dtype(source)
929-
target = _get_dtype(target)
930-
if is_categorical_dtype(source) and is_categorical_dtype(target):
931-
# ordered False for both
932-
return source.ordered is target.ordered
933-
return is_dtype_equal(source, target)
934-
935-
936901
def is_any_int_dtype(arr_or_dtype):
937902
"""Check whether the provided array or dtype is of an integer dtype.
938903
@@ -1498,60 +1463,6 @@ def is_numeric(x):
14981463
)
14991464

15001465

1501-
def is_datetimelike_v_object(a, b):
1502-
"""
1503-
Check if we are comparing a datetime-like object to an object instance.
1504-
1505-
Parameters
1506-
----------
1507-
a : array-like, scalar
1508-
The first object to check.
1509-
b : array-like, scalar
1510-
The second object to check.
1511-
1512-
Returns
1513-
-------
1514-
boolean
1515-
Whether we return a comparing a datetime-like to an object instance.
1516-
1517-
Examples
1518-
--------
1519-
>>> obj = object()
1520-
>>> dt = np.datetime64(pd.datetime(2017, 1, 1))
1521-
>>>
1522-
>>> is_datetimelike_v_object(obj, obj)
1523-
False
1524-
>>> is_datetimelike_v_object(dt, dt)
1525-
False
1526-
>>> is_datetimelike_v_object(obj, dt)
1527-
True
1528-
>>> is_datetimelike_v_object(dt, obj) # symmetric check
1529-
True
1530-
>>> is_datetimelike_v_object(np.array([dt]), obj)
1531-
True
1532-
>>> is_datetimelike_v_object(np.array([obj]), dt)
1533-
True
1534-
>>> is_datetimelike_v_object(np.array([dt]), np.array([obj]))
1535-
True
1536-
>>> is_datetimelike_v_object(np.array([obj]), np.array([obj]))
1537-
False
1538-
>>> is_datetimelike_v_object(np.array([dt]), np.array([1]))
1539-
False
1540-
>>> is_datetimelike_v_object(np.array([dt]), np.array([dt]))
1541-
False
1542-
"""
1543-
1544-
if not hasattr(a, "dtype"):
1545-
a = np.asarray(a)
1546-
if not hasattr(b, "dtype"):
1547-
b = np.asarray(b)
1548-
1549-
is_datetimelike = needs_i8_conversion
1550-
return (is_datetimelike(a) and is_object_dtype(b)) or (
1551-
is_datetimelike(b) and is_object_dtype(a)
1552-
)
1553-
1554-
15551466
def needs_i8_conversion(arr_or_dtype):
15561467
"""
15571468
Check whether the array or dtype should be converted to int64.

pandas/tests/dtypes/test_common.py

-17
Original file line numberDiff line numberDiff line change
@@ -527,23 +527,6 @@ def test_is_datetimelike_v_numeric():
527527
assert com.is_datetimelike_v_numeric(np.array([dt]), np.array([1]))
528528

529529

530-
def test_is_datetimelike_v_object():
531-
obj = object()
532-
dt = np.datetime64(pd.datetime(2017, 1, 1))
533-
534-
assert not com.is_datetimelike_v_object(dt, dt)
535-
assert not com.is_datetimelike_v_object(obj, obj)
536-
assert not com.is_datetimelike_v_object(np.array([dt]), np.array([1]))
537-
assert not com.is_datetimelike_v_object(np.array([dt]), np.array([dt]))
538-
assert not com.is_datetimelike_v_object(np.array([obj]), np.array([obj]))
539-
540-
assert com.is_datetimelike_v_object(dt, obj)
541-
assert com.is_datetimelike_v_object(obj, dt)
542-
assert com.is_datetimelike_v_object(np.array([dt]), obj)
543-
assert com.is_datetimelike_v_object(np.array([obj]), dt)
544-
assert com.is_datetimelike_v_object(np.array([dt]), np.array([obj]))
545-
546-
547530
def test_needs_i8_conversion():
548531
assert not com.needs_i8_conversion(str)
549532
assert not com.needs_i8_conversion(np.int64)

pandas/util/testing.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
is_categorical_dtype,
3434
is_datetime64_dtype,
3535
is_datetime64tz_dtype,
36-
is_datetimelike_v_numeric,
37-
is_datetimelike_v_object,
3836
is_extension_array_dtype,
3937
is_interval_dtype,
4038
is_list_like,
@@ -1172,12 +1170,7 @@ def assert_series_equal(
11721170
# we want to check only if we have compat dtypes
11731171
# e.g. integer and M|m are NOT compat, but we can simply check
11741172
# the values in that case
1175-
if (
1176-
is_datetimelike_v_numeric(left, right)
1177-
or is_datetimelike_v_object(left, right)
1178-
or needs_i8_conversion(left)
1179-
or needs_i8_conversion(right)
1180-
):
1173+
if needs_i8_conversion(left) or needs_i8_conversion(right):
11811174

11821175
# datetimelike may have different objects (e.g. datetime.datetime
11831176
# vs Timestamp) but will compare equal

0 commit comments

Comments
 (0)