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 a base Track class, remove all reprs #205

Merged
merged 4 commits into from
Apr 3, 2020
Merged

Conversation

rabitt
Copy link
Collaborator

@rabitt rabitt commented Apr 2, 2020

Implements #178 [EDIT by @lostanlen: closes #178]

All dataset Track classes now inherit from utils.Track, which has an automated implementation of __repr__, removing the need for new loaders to write this themselves 🎉

It has one peculiarity, which in my opinion ends up being kind of nice -
__repr__ will break if implemented Track properties do not have documentation, and our tests catch that.

@codecov
Copy link

codecov bot commented Apr 2, 2020

Codecov Report

Merging #205 into master will increase coverage by 0.10%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #205      +/-   ##
==========================================
+ Coverage   95.87%   95.97%   +0.10%     
==========================================
  Files          18       19       +1     
  Lines        1938     1938              
==========================================
+ Hits         1858     1860       +2     
+ Misses         80       78       -2     

@lostanlen
Copy link
Collaborator

lostanlen commented Apr 2, 2020

__repr__ will break if implemented Track properties do not have documentation, and our tests catch that.

😍

Copy link
Collaborator

@andreasjansson andreasjansson left a comment

Choose a reason for hiding this comment

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

Looks good, just a few minor nits!

mirdata/utils.py Outdated

for attr in attributes:
val = getattr(self, attr)
if isinstance(val, str):
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this be if not isinstance?

Copy link
Collaborator

Choose a reason for hiding this comment

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

if you support py2 still (do you?) you need to check baseinstance for basestring

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's right - I'm formatting strings with visible " around the values when printing

mirdata/utils.py Outdated


MIR_DATASETS_DIR = os.path.join(os.getenv('HOME', '/tmp'), 'mir_datasets')


class Track(object):
def __repr__(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

right now you're not truncating strings or anything right? if an object has a really long value it might hang ipython.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good point - will add this

mirdata/utils.py Outdated


MIR_DATASETS_DIR = os.path.join(os.getenv('HOME', '/tmp'), 'mir_datasets')


class Track(object):
Copy link
Collaborator

Choose a reason for hiding this comment

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

i might have put this in track.py. utils.py is a bit of an antipattern, or at least good to avoid.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good idea - moving!

mirdata/utils.py Outdated
if val.__doc__ is None:
raise ValueError("{} has no documentation".format(prop))

val_type_str = val.__doc__.split(':')[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you validate that docstrings are correctly formatted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nope - should I? if it doesn't have a : character somewhere it'll just print the whole docstring, which is ugly but not broken

tests/test_beatles.py Show resolved Hide resolved
Copy link
Collaborator

@lostanlen lostanlen left a comment

Choose a reason for hiding this comment

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

LGTM. I concur with Rachel that it's better to test the base class rather than specific implementations. Also, i think we can live with a change in __repr__ between alpha and 0.2.0
I don't expect that users will call the __repr__ function programatically anyways.

Merge at your convenience

@rabitt rabitt merged commit e9c8c85 into master Apr 3, 2020
@rabitt rabitt deleted the rachel/track-base-class branch April 7, 2020 11:12
nkundiushuti pushed a commit that referenced this pull request Nov 4, 2020
 
add a base Track class, remove all reprs (#205)

* add a base Track class, remove all reprs
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.

Track base class
3 participants