Helper function to handle data keyword argument

def _process_data(*kwarg_names):
    """Helper function to handle data keyword argument
    """
    def _data_decorator(func):
        @functools.wraps(func)
        def _mark_with_data(*args, **kwargs):
            data = kwargs.pop('data', None)
            if data is None:
                return func(*args, **kwargs)
            else:
                data_args = [data[i] if hashable(data, i) else i for i in args]
                data_kwargs = {
                   kw: data[kwargs[kw]] if hashable(data, kwargs[kw]) else kwargs[kw] for kw in set(kwarg_names).intersection(list(kwargs.keys()))
                }
                try:
                    # if any of the plots want to use the index_data, they can
                    # use it by referring to this attribute.
                    data_kwargs['index_data'] = data.index
                except AttributeError as e:
                    pass
                kwargs_update = kwargs.copy()
                kwargs_update.update(data_kwargs)
                return func(*data_args, **kwargs_update)

        return _mark_with_data
    return _data_decorator