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

[FIX] data/io.py Metadata file not saved anymore when it is empty #2002

Merged
merged 1 commit into from
Feb 9, 2017
Merged

[FIX] data/io.py Metadata file not saved anymore when it is empty #2002

merged 1 commit into from
Feb 9, 2017

Conversation

jerneju
Copy link
Contributor

@jerneju jerneju commented Feb 7, 2017

Issue

Do not save the metadata file (when saving the data) if this is empty (0 Bytes)

Description of changes

Change if statement and add third condition. It implies that attribute should not be empty. Add test file to check if metadata is saved when empty

Includes
  • Code changes
  • Tests
  • Documentation

@CLAassistant
Copy link

CLAassistant commented Feb 7, 2017

CLA assistant check
All committers have signed the CLA.

@codecov-io
Copy link

codecov-io commented Feb 7, 2017

Codecov Report

Merging #2002 into master will not change coverage.

@@           Coverage Diff           @@
##           master    #2002   +/-   ##
=======================================
  Coverage   89.53%   89.53%           
=======================================
  Files          91       91           
  Lines        9199     9199           
=======================================
  Hits         8236     8236           
  Misses        963      963

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 7d1b87d...1dc53af. Read the comment docs.

table = Table("iris")
fname = path.join(tempdir, "out.tab")
TabReader.write_table_metadata(fname, table)
self.assertEqual(path.isfile(fname + ".metadata"), True)
Copy link
Member

Choose a reason for hiding this comment

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

You could use self.assertTrue

table = Table("titanic")
fname = path.join(tempdir, "out.tab")
TabReader.write_table_metadata(fname, table)
self.assertEqual(path.isfile(fname + ".metadata"), False)
Copy link
Member

Choose a reason for hiding this comment

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

You could use self.assertFalse

@@ -373,7 +373,7 @@ def write(cls, filename, data):

@classmethod
def write_table_metadata(cls, filename, data):
if isinstance(filename, str) and hasattr(data, 'attributes'):
if isinstance(filename, str) and hasattr(data, 'attributes') and data.attributes:
Copy link
Member

Choose a reason for hiding this comment

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

hasattr(data, 'attributes') and data.attributes

could be simplified to

getattr(data, 'attributes', None)

@@ -0,0 +1,36 @@
# Test methods with long descriptive names can omit docstrings
Copy link
Member

Choose a reason for hiding this comment

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

Is there a special reason this tests were not placed in Orange/tests/test_tab_reader.py? They only test TabReaders functionality and all other TabReader tests are in that file.

DiscreteVariable._clear_cache()

def test_metadata(self):
tempdir = tempfile.mkdtemp()
Copy link
Member

Choose a reason for hiding this comment

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

This tests assume that iris has metadata and titanic has not. If this would change in the future (if we added metadata for titanic as well), the second test would fail and will need to be fixed, even though the change would have nothing to do with the saving of metadata.

I suggest that you manually set the attributes dict to whatever you need in a test and then do the testing. This way, attributes dict will be the one you expect it to be, even if the datasets change in the future.

Issue
Do not save the metadata file (when saving the data) if this is empty (0 Bytes)

Description of changes
Change if statement and add third condition. It implies that attribute should not be empty.
@astaric astaric merged commit 5dae6df into biolab:master Feb 9, 2017
@jerneju jerneju deleted the metadata-save branch April 20, 2017 13:44
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