Skip to content

Commit c6ca378

Browse files
mroeschkejreback
authored andcommitted
CLN: Address some TODO comments (#23208)
1 parent b5e1fc2 commit c6ca378

File tree

7 files changed

+29
-85
lines changed

7 files changed

+29
-85
lines changed

pandas/core/common.py

-26
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,6 @@ def consensus_name_attr(objs):
6868
return name
6969

7070

71-
# TODO: only used once in frame.py; belongs elsewhere?
72-
def get_info_slice(obj, indexer):
73-
"""Slice the info axis of `obj` with `indexer`."""
74-
if not hasattr(obj, '_info_axis_number'):
75-
msg = 'object of type {typ!r} has no info axis'
76-
raise TypeError(msg.format(typ=type(obj).__name__))
77-
slices = [slice(None)] * obj.ndim
78-
slices[obj._info_axis_number] = indexer
79-
return tuple(slices)
80-
81-
8271
def maybe_box(indexer, values, obj, key):
8372

8473
# if we have multiples coming back, box em
@@ -432,21 +421,6 @@ def random_state(state=None):
432421
"RandomState, or None")
433422

434423

435-
# TODO: only used once in indexes.api; belongs elsewhere?
436-
def get_distinct_objs(objs):
437-
"""
438-
Return a list with distinct elements of "objs" (different ids).
439-
Preserves order.
440-
"""
441-
ids = set()
442-
res = []
443-
for obj in objs:
444-
if not id(obj) in ids:
445-
ids.add(id(obj))
446-
res.append(obj)
447-
return res
448-
449-
450424
def _pipe(obj, func, *args, **kwargs):
451425
"""
452426
Apply a function ``func`` to object ``obj`` either by passing obj as the

pandas/core/frame.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -3157,6 +3157,14 @@ def select_dtypes(self, include=None, exclude=None):
31573157
4 True 1.0
31583158
5 False 2.0
31593159
"""
3160+
def _get_info_slice(obj, indexer):
3161+
"""Slice the info axis of `obj` with `indexer`."""
3162+
if not hasattr(obj, '_info_axis_number'):
3163+
msg = 'object of type {typ!r} has no info axis'
3164+
raise TypeError(msg.format(typ=type(obj).__name__))
3165+
slices = [slice(None)] * obj.ndim
3166+
slices[obj._info_axis_number] = indexer
3167+
return tuple(slices)
31603168

31613169
if not is_list_like(include):
31623170
include = (include,) if include is not None else ()
@@ -3205,7 +3213,7 @@ def is_dtype_instance_mapper(idx, dtype):
32053213
exclude_these.iloc[idx] = not any(map(f, exclude))
32063214

32073215
dtype_indexer = include_these & exclude_these
3208-
return self.loc[com.get_info_slice(self, dtype_indexer)]
3216+
return self.loc[_get_info_slice(self, dtype_indexer)]
32093217

32103218
def _box_item_values(self, key, values):
32113219
items = self.columns[self.columns.get_loc(key)]

pandas/core/generic.py

-10
Original file line numberDiff line numberDiff line change
@@ -4069,16 +4069,6 @@ def _reindex_with_indexers(self, reindexers, fill_value=None, copy=False,
40694069

40704070
return self._constructor(new_data).__finalize__(self)
40714071

4072-
# TODO: unused; remove?
4073-
def _reindex_axis(self, new_index, fill_method, axis, copy):
4074-
new_data = self._data.reindex_axis(new_index, axis=axis,
4075-
method=fill_method, copy=copy)
4076-
4077-
if new_data is self._data and not copy:
4078-
return self
4079-
else:
4080-
return self._constructor(new_data).__finalize__(self)
4081-
40824072
def filter(self, items=None, like=None, regex=None, axis=None):
40834073
"""
40844074
Subset rows or columns of dataframe according to labels in

pandas/core/indexes/api.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,23 @@ def _get_objs_combined_axis(objs, intersect=False, axis=0, sort=True):
5353
return _get_combined_index(obs_idxes, intersect=intersect, sort=sort)
5454

5555

56+
def _get_distinct_objs(objs):
57+
"""
58+
Return a list with distinct elements of "objs" (different ids).
59+
Preserves order.
60+
"""
61+
ids = set()
62+
res = []
63+
for obj in objs:
64+
if not id(obj) in ids:
65+
ids.add(id(obj))
66+
res.append(obj)
67+
return res
68+
69+
5670
def _get_combined_index(indexes, intersect=False, sort=False):
5771
# TODO: handle index names!
58-
indexes = com.get_distinct_objs(indexes)
72+
indexes = _get_distinct_objs(indexes)
5973
if len(indexes) == 0:
6074
index = Index([])
6175
elif len(indexes) == 1:

pandas/core/indexes/timedeltas.py

+3-43
Original file line numberDiff line numberDiff line change
@@ -511,60 +511,20 @@ def _maybe_cast_slice_bound(self, label, side, kind):
511511

512512
return label
513513

514-
def _get_string_slice(self, key, use_lhs=True, use_rhs=True):
515-
freq = getattr(self, 'freqstr',
516-
getattr(self, 'inferred_freq', None))
514+
def _get_string_slice(self, key):
517515
if is_integer(key) or is_float(key) or key is NaT:
518516
self._invalid_indexer('slice', key)
519-
loc = self._partial_td_slice(key, freq, use_lhs=use_lhs,
520-
use_rhs=use_rhs)
517+
loc = self._partial_td_slice(key)
521518
return loc
522519

523-
def _partial_td_slice(self, key, freq, use_lhs=True, use_rhs=True):
520+
def _partial_td_slice(self, key):
524521

525522
# given a key, try to figure out a location for a partial slice
526523
if not isinstance(key, compat.string_types):
527524
return key
528525

529526
raise NotImplementedError
530527

531-
# TODO(wesm): dead code
532-
# parsed = _coerce_scalar_to_timedelta_type(key, box=True)
533-
534-
# is_monotonic = self.is_monotonic
535-
536-
# # figure out the resolution of the passed td
537-
# # and round to it
538-
539-
# # t1 = parsed.round(reso)
540-
541-
# t2 = t1 + to_offset(parsed.resolution) - Timedelta(1, 'ns')
542-
543-
# stamps = self.asi8
544-
545-
# if is_monotonic:
546-
547-
# # we are out of range
548-
# if (len(stamps) and ((use_lhs and t1.value < stamps[0] and
549-
# t2.value < stamps[0]) or
550-
# ((use_rhs and t1.value > stamps[-1] and
551-
# t2.value > stamps[-1])))):
552-
# raise KeyError
553-
554-
# # a monotonic (sorted) series can be sliced
555-
# left = (stamps.searchsorted(t1.value, side='left')
556-
# if use_lhs else None)
557-
# right = (stamps.searchsorted(t2.value, side='right')
558-
# if use_rhs else None)
559-
560-
# return slice(left, right)
561-
562-
# lhs_mask = (stamps >= t1.value) if use_lhs else True
563-
# rhs_mask = (stamps <= t2.value) if use_rhs else True
564-
565-
# # try to find a the dates
566-
# return (lhs_mask & rhs_mask).nonzero()[0]
567-
568528
@Substitution(klass='TimedeltaIndex')
569529
@Appender(_shared_docs['searchsorted'])
570530
def searchsorted(self, value, side='left', sorter=None):

pandas/core/internals/blocks.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -2812,9 +2812,7 @@ def _astype(self, dtype, mgr=None, **kwargs):
28122812
def _can_hold_element(self, element):
28132813
tipo = maybe_infer_dtype_type(element)
28142814
if tipo is not None:
2815-
# TODO: this still uses asarray, instead of dtype.type
2816-
element = np.array(element)
2817-
return element.dtype == _NS_DTYPE or element.dtype == np.int64
2815+
return tipo == _NS_DTYPE or tipo == np.int64
28182816
return (is_integer(element) or isinstance(element, datetime) or
28192817
isna(element))
28202818

pandas/tests/frame/test_mutate_columns.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def test_pop(self):
233233
self.frame['foo'] = 'bar'
234234
self.frame.pop('foo')
235235
assert 'foo' not in self.frame
236-
# TODO assert self.frame.columns.name == 'baz'
236+
assert self.frame.columns.name == 'baz'
237237

238238
# gh-10912: inplace ops cause caching issue
239239
a = DataFrame([[1, 2, 3], [4, 5, 6]], columns=[

0 commit comments

Comments
 (0)