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

Improving the behaviour of an empty InferenceData object. (Issue no 486). #577

Merged
merged 5 commits into from
Feb 21, 2019

Conversation

Ban-zee
Copy link
Contributor

@Ban-zee Ban-zee commented Jan 31, 2019

Addressing issue #486

@canyon289
Copy link
Member

@Ban-zee Please add tests as well

@ColCarroll
Copy link
Member

Thanks for this contribution! A few suggestions:

  • It is helpful if the title and description say what the pull request is doing -- linking to the issue it fixes is helpful, but being able to search for things in the future, as well as having meaningful git commit messages is important.
  • I would make this change to the InferenceData object directly

@Ban-zee
Copy link
Contributor Author

Ban-zee commented Feb 1, 2019

Definitely, will keep that in mind in the future. I'll make the necessary changes.

@canyon289
Copy link
Member

canyon289 commented Feb 4, 2019

@Ban-zee If you want to practice you can change the title of this PR and amend your commit to have a more useful message :)

@Ban-zee
Copy link
Contributor Author

Ban-zee commented Feb 5, 2019

A minor question, exactly what test should I include as the test for checking an inference object's existence is already included in test_data.py. TIA.

@canyon289
Copy link
Member

canyon289 commented Feb 6, 2019

I would add a meaningful test for these lines that are currently not tested
https://coveralls.io/builds/21387295/source?filename=arviz%2Fdata%2Fio_netcdf.py#L47

Reading this over a bit more too can we add a doc string that briefly explains why the if else is there?

To consolidate comments here's what I would like for an approval

  1. Change PR name to a human understandable one
  2. Change git commit message to be human understandable
  3. Add test for else block
  4. Add comment explaining case that if else block is handling

@Ban-zee Ban-zee changed the title Issue no #486 Improving the behaviour of an empty InferenceData object. (Issue no 486). Feb 6, 2019
@canyon289
Copy link
Member

@Ban-zee Thanks for the title change :)
If you need help with the other asks let us know! We're here to help

@Ban-zee
Copy link
Contributor Author

Ban-zee commented Feb 9, 2019 via email

@canyon289
Copy link
Member

@Ban-zee Don't worry about how long you keep the PR open, there's no timeline in open source!

For testing, are you familiar with pytest or testing principles in general? Trying to get a baseline of where you're at so I can guide you appropriately

@Ban-zee
Copy link
Contributor Author

Ban-zee commented Feb 9, 2019 via email

@canyon289
Copy link
Member

When you do a "destructive" git command like amend you have to force push. Just be careful because if you mess up the command its becomes more difficult to go back, and in some cases impossible.

For the data functions I would look at this module and this test. It'll give you an idea how things are implemented

https://github.com/arviz-devs/arviz/blob/master/arviz/tests/test_data.py#L651

@ahartikainen
Copy link
Contributor

Let's say it is impossible. (It is just really really hard, but doable)

@Ban-zee
Copy link
Contributor Author

Ban-zee commented Feb 11, 2019 via email

* Made changes to inference_data.py directly instead of io_netcdf.py as suggested.
* Added comments.
* Not included the tests yet!
*Not included tests yet!!
@Ban-zee
Copy link
Contributor Author

Ban-zee commented Feb 18, 2019

Getting the following error: "No output has been received in the last 10m0s, this potentially indicates a stalled build or something wrong with the build itself." Any idea on what should be done?

@ahartikainen
Copy link
Contributor

That happens sometimes (travis freezes). Restarting the job usually works (might need admin rights, so usually someone from the devteam can do it).

@Ban-zee
Copy link
Contributor Author

Ban-zee commented Feb 18, 2019

Thank you.

@ColCarroll
Copy link
Member

Hrm... fails on Python 3.5, but not Python 3.6. I restarted in case it is a flaky test, but here's the message:

=================================== FAILURES ===================================
______________________ TestIONetCDFUtils.test_io_function ______________________
self = <arviz.tests.test_data.TestIONetCDFUtils object at 0x7f4bfb122668>
data = <class 'arviz.tests.test_data.TestIONetCDFUtils.data.<locals>.Data'>
eight_schools_params = {'J': 8, 'sigma': array([15., 10., 16., 11.,  9., 11., 10., 18.]), 'y': array([28.,  8., -3.,  7., -1.,  1., 18., 12.])}
    def test_io_function(self, data, eight_schools_params):
        inference_data = self.get_inference_data(  # pylint: disable=W0612
            data, eight_schools_params
        )
        assert hasattr(inference_data, "posterior")
        here = os.path.dirname(os.path.abspath(__file__))
        data_directory = os.path.join(here, "saved_models")
        filepath = os.path.join(data_directory, "io_function_testfile.nc")
        # az -function
        to_netcdf(inference_data, filepath)
        assert os.path.exists(filepath)
        assert os.path.getsize(filepath) > 0
        inference_data2 = from_netcdf(filepath)
>       assert hasattr(inference_data2, "posterior")
E       AssertionError: assert False
E        +  where False = hasattr(Inference data with groups:\n	> posterior_predictive, 'posterior')

@Ban-zee
Copy link
Contributor Author

Ban-zee commented Feb 18, 2019

Any idea on why the test fails in python 3.5 but not in 3.6?

data.to_netcdf(filename, mode=mode, group=group, **kwargs)
data.close()
mode = "a"
return filename
Copy link
Contributor

Choose a reason for hiding this comment

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

here is indentation error.

You could return filename at the end of the function.

else: # creates a netcdf file for an empty InferenceData object.
empty_netcdf_file = nc.Dataset(filename, mode="w", format="NETCDF4")
empty_netcdf_file.close()
return filename
Copy link
Contributor

@ahartikainen ahartikainen Feb 18, 2019

Choose a reason for hiding this comment

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

remove the first return filename and return this outside the if-else block. (indent back)

@Ban-zee
Copy link
Contributor Author

Ban-zee commented Feb 19, 2019

Made the changes. Thank you for your help. Are there any more changes to be made prior to merging?

@Ban-zee
Copy link
Contributor Author

Ban-zee commented Feb 21, 2019

Any other change I have to make before merging?

@ColCarroll ColCarroll merged commit 000b282 into arviz-devs:master Feb 21, 2019
@ColCarroll
Copy link
Member

This looks good -- thank you for the contribution @Ban-zee!

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.

4 participants