Description
xref #3004
xref #841
xref #7873
xref #7223
xref #8815
Building on @immerrr's excellent refactor in #8753, I would like to propose adding a get_nearest
method to pandas.Index that does nearest neighbor lookups. The idea is that nearest neighbor lookups are usually the desirable/sane thing to do when using inexact indexes. Eventually, we might want to add an alternative "wrapper index" (like IntervalIndex), e.g., NearestNeighborIndex
which switches the default behavior; this would be an intermediate step in that direction.
The implementation would be a simple wrapper that calls Index.get_slice_bound
twice, once to the left and once to the right. Ideally, this would this would even work for array-like arguments, though perhaps there should be separate get_nearest_loc
and get_nearest_indexer
methods.