Skip to content

ENH: provide standard BaseIndexers in pandas.api.indexers #33201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AlexKirko opened this issue Apr 1, 2020 · 1 comment · Fixed by #33236
Closed

ENH: provide standard BaseIndexers in pandas.api.indexers #33201

AlexKirko opened this issue Apr 1, 2020 · 1 comment · Fixed by #33236
Assignees
Labels
Enhancement Window rolling, ewma, expanding
Milestone

Comments

@AlexKirko
Copy link
Member

Problem description

During my work on generalizing our rolling window functions, @mroeschke and @jreback have pointed out that it would be useful to expose a couple BaseIndexer subclasses as a part of our api (in pandas.api.indexers, to be specific). For instance, forward-looking windows are fairly common in signal analysis and the like, and it would benefit users if we had a default implementation of those.

This is the implementation I'm currently using for testing:

    class ForwardIndexer(BaseIndexer):
        def get_window_bounds(self, num_values, min_periods, center, closed):
            start = np.empty(num_values, dtype=np.int64)
            end = np.empty(num_values, dtype=np.int64)
            for i in range(num_values):
                if i + min_periods <= num_values:
                    start[i] = i
                    end[i] = min(i + self.window_size, num_values)
                else:
                    start[i] = i
                    end[i] = i + 1
            return start, end

This should be rewritten to avoid the for loop, as it slows the function down a lot.

We could also add a backward indexer for completeness or skip it, because it can be done by supplying an integer when creating the rolling window object. Tell me what you think.

I'd be happy to submit a PR with a proposed implementation in a day or two.

Implementation details

I think we can put the implementation of the new class/classes in pandas.core.window.indexers.

Cross-references

xref #32865
xref #33180

@mroeschke mroeschke added Enhancement Window rolling, ewma, expanding labels Apr 1, 2020
@AlexKirko
Copy link
Member Author

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants