Exemplo n.º 1
0
def get_neighbor(index: pandas.Index, item: Any, previous: bool = True) -> Any:
    """
		Return the neighboring value to `item`.
	Parameters
	----------
	index: The full index of the series. NOT just the index of detected values
	item
	previous

	Returns
	-------

	"""
    # Get the integer position of the item
    index = list(
        index
    )  # pandas.Index uses circular indexing, so the last key is treated as being prior to the initial key.
    offset = -1 if previous else 1

    location = index.index(item)
    if location != 0:
        location += offset
    try:
        return index[location]
    except IndexError:
        return item