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

Issue #260 More python 3 compatibility fix #683

Merged
merged 5 commits into from
Feb 1, 2016

Conversation

jbarnoud
Copy link
Contributor

Mostly bytes/strings issues

Most parser are now python 3 compatible. The main test suites that still fail are test_streamio.py and some analyses tests. They can potentially reveal hidden ugly stuff...

When we open a file (with open or anyopen), we must specify if it is a binary or a text file as they are handled in a different way in python 3.

Mostly bytes/strings issues
@@ -171,6 +171,10 @@ def sl():
assert_raises(TypeError, sl)

def _check_getitem(self, sl):
try:
print(sl.dtype)
Copy link
Member

Choose a reason for hiding this comment

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

What's this? debugging?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops... I'll remove it with the next commit.

@jbarnoud jbarnoud changed the title Issue $260 More python 3 compatibility fix Issue #260 More python 3 compatibility fix Jan 29, 2016
@@ -306,7 +306,7 @@ def make_density(self):
warnings.warn(msg)
return

dedges = map(np.diff, self.edges)
dedges = list(map(np.diff, self.edges))
Copy link
Member

Choose a reason for hiding this comment

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

This is a complicated way for a list comprehension [np.diff(e) for e in self.edges]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On 29/01/16 22:49, kain88-de wrote:

In package/MDAnalysis/analysis/density.py
#683 (comment):

@@ -306,7 +306,7 @@ def make_density(self):
warnings.warn(msg)
return

  •    dedges = map(np.diff, self.edges)
    
  •    dedges = list(map(np.diff, self.edges))
    

This is a complicated way for a list comprehension |[np.diff(e) for e
in self.edges]|


Reply to this email directly or view it on GitHub
https://github.com/MDAnalysis/mdanalysis/pull/683/files#r51320581.

I do not have the reflex yet.

Copy link
Member

Choose a reason for hiding this comment

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

basically every map can be replaced with it.

@jbarnoud
Copy link
Contributor Author

@richardjgowers @kain88-de I pushed fixes for your comments. If the tests pass it is good for review.

@@ -61,7 +61,8 @@ def parse(self):
:Returns: MDAnalysis internal *structure* dict as defined here.
"""
# Open and check psf validity
with openany(self.filename, 'r') as psffile:
with openany(self.filename, 'rt') as psffile:
print(type(psffile))
Copy link
Member

Choose a reason for hiding this comment

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

Debug line

@richardjgowers
Copy link
Member

Looks good if @kain88-de is happy too

@@ -116,8 +116,12 @@ def _read_offsets(self, store=False):
np.savez(offsets_filename(self.filename),
offsets=offsets, size=size, ctime=ctime)
except Exception as e:
warnings.warn("Couldn't save offsets because: {}".format(
e.message))
try:
Copy link
Member

Choose a reason for hiding this comment

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

Did the exception format change in Py3? Is there something in six so that we don't have to write the try block everytime? How do other packages deal with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that some exceptions do not have a message attribute. I was receiving errors about PermissionError not having it.

Copy link
Member

Choose a reason for hiding this comment

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

So coincidence I just triggered the exception under python 2 and got a warning that BaseException.message deprecated is. So I guess they removed in Python 3. But that means that the code in your except branch should work under python 2.7 as well.

@kain88-de
Copy link
Member

Looks good to me besides the comment about the exception.

richardjgowers added a commit that referenced this pull request Feb 1, 2016
Issue #260 More python 3 compatibility fix
@richardjgowers richardjgowers merged commit 68b587a into MDAnalysis:develop Feb 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants