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 to_dataframe to InferenceData #1395

Merged
merged 15 commits into from
Sep 28, 2020
Merged

Add to_dataframe to InferenceData #1395

merged 15 commits into from
Sep 28, 2020

Conversation

ahartikainen
Copy link
Contributor

@ahartikainen ahartikainen commented Sep 25, 2020

Description

Add .to_dataframe function to InferenceData. The result is a dataframe in a "wide" format.

This PR also adds __getitem__ magic for the InferenceData.

Checklist

  • Follows official PR format
  • Includes a sample plot to visually illustrate the changes (only for plot-related functions)
  • New features are properly documented (with an example if appropriate)?
  • Includes new or updated tests to cover the new feature
  • Code style correct (follows pylint and black guidelines)
  • Changes are listed in changelog

image

image

image

image

image

@ahartikainen ahartikainen changed the title Add to_dataframe to InferanceData Add to_dataframe to InferenceData Sep 25, 2020
@codecov
Copy link

codecov bot commented Sep 26, 2020

Codecov Report

Merging #1395 into master will increase coverage by 0.01%.
The diff coverage is 92.06%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1395      +/-   ##
==========================================
+ Coverage   91.63%   91.65%   +0.01%     
==========================================
  Files         105      105              
  Lines       10965    11022      +57     
==========================================
+ Hits        10048    10102      +54     
- Misses        917      920       +3     
Impacted Files Coverage Δ
arviz/data/inference_data.py 85.14% <91.93%> (+1.00%) ⬆️
arviz/data/base.py 97.50% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24ce65a...b3c6e28. Read the comment docs.

Copy link
Member

@OriolAbril OriolAbril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Comment on lines +193 to +197
def __getitem__(self, key):
"""Get item by key."""
if key not in self._groups_all:
raise KeyError(key)
return getattr(self, key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

arviz/data/inference_data.py Show resolved Hide resolved
arviz/data/inference_data.py Outdated Show resolved Hide resolved
arviz/data/inference_data.py Outdated Show resolved Hide resolved
)

if not group_names:
raise TypeError("No valid groups found: {}".format(groups))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this logic ok?

posterior + observed_data --> df from posterior

observed_data -> TypeError

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is ok, given that it fits our goals and we document it. My only question not really knowing yet how panel works is if ppc checks will be possible with it if observed_data is not in the dataframe

Copy link
Contributor Author

@ahartikainen ahartikainen Sep 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Panel works with xarray too. My gist was just short cutting some code with data frame.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, cool!

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

Successfully merging this pull request may close these issues.

2 participants