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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added the test
Ban-zee committed Feb 18, 2019
commit cc51d89699efb84f66155082aebfb2d990ab3ba4
2 changes: 1 addition & 1 deletion arviz/data/inference_data.py
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ def to_netcdf(self, filename, compress=True):
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: # an empty netcdf file is created in case an empty inference data object is encountered.
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)

2 changes: 0 additions & 2 deletions arviz/data/io_netcdf.py
Original file line number Diff line number Diff line change
@@ -2,8 +2,6 @@
import warnings
from .inference_data import InferenceData
from .converters import convert_to_inference_data
import os
import netCDF4 as nc


def from_netcdf(filename):
11 changes: 11 additions & 0 deletions arviz/tests/test_data.py
Original file line number Diff line number Diff line change
@@ -691,6 +691,17 @@ def test_io_method(self, data, eight_schools_params):
os.remove(filepath)
assert not os.path.exists(filepath)

def test_empty_inference_data_object(self):
inference_data = InferenceData()
here = os.path.dirname(os.path.abspath(__file__))
data_directory = os.path.join(here, "saved_models")
filepath = os.path.join(data_directory, "empty_test_file.nc")
assert not os.path.exists(filepath)
inference_data.to_netcdf(filepath)
assert os.path.exists(filepath)
os.remove(filepath)
assert not os.path.exists(filepath)


class TestPyMC3NetCDFUtils:
@pytest.fixture(scope="class")