Skip to content
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

Adding a IamSlice feature #630

Closed
danielhuppmann opened this issue Feb 16, 2022 · 4 comments
Closed

Adding a IamSlice feature #630

danielhuppmann opened this issue Feb 16, 2022 · 4 comments

Comments

@danielhuppmann
Copy link
Member

Description

We often want to know which elements exist on an dimension after filtering, e.g., which variables exist for a specific region (see IAMconsortium/nomenclature#99). This can be done by the following

vars = df.filter(region="Region A").variable

However, this is inefficient because this creates a full (downselected) copy of the (timeseries) data and meta tables.

Proposed Solution

A new class IamSlice which is a derivative of the pd.MultiIndex of the internal _data pd.Series. The IamSlice is returned by the method slice(), which takes the same arguments as filter().

Expected usage

vars = df.slice(region="Region A").variable
@gidden
Copy link
Member

gidden commented Feb 16, 2022

+1, great idea!

@coroa
Copy link
Collaborator

coroa commented Mar 3, 2022

I like the idea in general, but am wondering whether an underlying boolean mask, with maybe a method to extract the indices would not be more composable. and i would also argue for either accepting a slice as first positional argument to df.filter or again to df.__getitem__, so that:

df[df.slice(region="...")] == df.filter(region="...")

@danielhuppmann
Copy link
Member Author

I like your idea about a boolean mask, but I would not how to implement it...

On the second idea about allowing df[df.slice()], that sounds great and easily doable...

@danielhuppmann
Copy link
Member Author

Closed via #637

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants