Skip to content

RF: Use python properties, rather than set/get methods #353

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

Merged
merged 9 commits into from
Oct 17, 2015
Merged

RF: Use python properties, rather than set/get methods #353

merged 9 commits into from
Oct 17, 2015

Conversation

bcipolli
Copy link
Contributor

@bcipolli bcipolli commented Oct 7, 2015

numDA, version, and filename properties on GIFTI have set_ and get_ methods. Seems cleaner (and more pythonic) to use Python properties instead.

Question: is GIFTI support officially published? I.e. do I need to add deprecation warnings for the old methods, and deprecation tests?

Also renamed tests to be clear that they're testing the loading of these properties, not necessarily of their setting or saving.

@matthew-brett
Copy link
Member

Sorry to say, but yes, we have advertised the GIFTI support, and people have used it, so I think we do have to deprecate the get_ / set_ methods...

@bcipolli
Copy link
Contributor Author

bcipolli commented Oct 7, 2015

OK. Is it worth it to make this change, in this case? Happy to deprecate & test, but also OK to toss. I'm just working through the code on my way to load/save GIFTI.

@matthew-brett
Copy link
Member

If you have the heart to do the deprecations, I think it's an improvement...

@bcipolli
Copy link
Contributor Author

bcipolli commented Oct 7, 2015

I sure do! Will get to that tonight or tomorrow, then :)

@bcipolli
Copy link
Contributor Author

bcipolli commented Oct 7, 2015

Added the get/set deprecations and deprecation tests.

@@ -427,14 +425,12 @@ def add_gifti_data_array(self, dataarr):
"""
if isinstance(dataarr, GiftiDataArray):
self.darrays.append(dataarr)
self.numDA += 1
Copy link
Member

Choose a reason for hiding this comment

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

numDA being tested properly already?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about tests, will check.
This line was removed as I made numDA a computed read-only property.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, sorry to be confusing - I saw you didn't need the line, but I was wondering if there were tests to make sure the computation was working right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There were not; I just added some.

@bcipolli
Copy link
Contributor Author

bcipolli commented Oct 9, 2015

I updated some other functions that are better as properties and added basic tests. Please take another look when possible!

else:
print("Not a valid GiftiLabelTable instance")
if not isinstance(labeltable, GiftiLabelTable):
raise ValueError("Not a valid GiftiLabelTable instance")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note the change from print to ValueError here.

@bcipolli bcipolli changed the title Use python properties, rather than set/get methods RF: Use python properties, rather than set/get methods Oct 9, 2015
self.red = rgba[0]
self.green = rgba[1]
self.blue = rgba[2]
self.alpha = rgba[3]
Copy link
Member

Choose a reason for hiding this comment

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

Personal preference, feel free to reject:

self.red, self.green, self.blue, self.alpha = rgba

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call!

@effigies
Copy link
Member

Read-through done. Logic looks good.

@bcipolli
Copy link
Contributor Author

Thanks @effigies ; I just updated the rgba logic and tests, added requested check for NumberOfDataArrays (and added a test), and opened #357 so we can add more 'malformed' GIFTI tests.

@bcipolli
Copy link
Contributor Author

Updated based on last comments.


# Test default value
gl4 = GiftiLabel()
assert_is_none(gl4.rgba[0])
Copy link
Member

Choose a reason for hiding this comment

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

2.6 seems upset.

assert_true(gl4.rgba[0] is None)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I get for trying to be too fancy :)

@effigies
Copy link
Member

Okay, this LGTM.

@matthew-brett The Travis build seems to be failing on unrelated things. (Happening here and on #354.)

effigies added a commit that referenced this pull request Oct 17, 2015
RF: Deprecate get/set methods in favor of Python properties

Test consistency of data array counter
Warn on inconsistent NumberofDataArrays and DataArray elements
Remove commented code from nibabel/gifti/gifti.py
@effigies effigies merged commit 8040f6d into nipy:master Oct 17, 2015
@bcipolli bcipolli deleted the gifti-fix2 branch October 17, 2015 12:30
grlee77 pushed a commit to grlee77/nibabel that referenced this pull request Mar 15, 2016
RF: Deprecate get/set methods in favor of Python properties

Test consistency of data array counter
Warn on inconsistent NumberofDataArrays and DataArray elements
Remove commented code from nibabel/gifti/gifti.py
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.

3 participants