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

Add data access through BIDSFile #433

Closed
tyarkoni opened this issue Apr 10, 2019 · 5 comments
Closed

Add data access through BIDSFile #433

tyarkoni opened this issue Apr 10, 2019 · 5 comments

Comments

@tyarkoni
Copy link
Collaborator

For BIDSFile objects associated with files containing text data (e.g., .tsv, tsv.gz, .json, etc.), users should be able to directly retrieve the contents (as a DataFrame or dict) via a .get_data() method.

@effigies
Copy link
Collaborator

effigies commented Apr 10, 2019

Is the polymorphism based on file extension a good idea? Suppose I do a query that can get multiple file types and don't think to check. If I always (or at least in some mistaken cases) get something useful with .get_data(), it might be a few steps before I try to do something with it that raises an error.

For example, if I thought I was reading a JSON file but instead read a TSV file, I might try to set a value in the dict, which actually creates a column in the DataFrame.

We could instead try something like:

def get_df(self):
    if self.ext not in ('.tsv', '.tsv.gz'):
        raise ValueError
    # return pandas.DataFrame

def get_text(self):
    # return contents as str
def get_dict(self):
    # return dict interpretation
def get_image(self):
    # return nibabel image

Some of these could still apply to multiple image types, but the output type would be predictable.

@tyarkoni
Copy link
Collaborator Author

I'm not sure I see much of a use case for get_dict or get_text (they're a single line of code to read in, whereas updating the DF columns etc. based on metadata can involve a bit more work), and having a whole family of methods seems to me to unnecessarily clutter the API. But I'd be fine saying that you can only get back a pandas DF from get_data(), and anything else will raise an error (this is actually how I just started to implement it). I'd also be fine renaming it to get_df() to reduce ambiguity. We can always add other methods later.

@effigies
Copy link
Collaborator

Sure, makes sense. I would prefer get_df() to be explicit. I think we do provide access to nibabel images already.

@tyarkoni
Copy link
Collaborator Author

Yeah, there are get_image() and get_metadata() methods.

@tyarkoni
Copy link
Collaborator Author

Closed in #432.

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

No branches or pull requests

2 participants