Skip to content

Commit

Permalink
STYLE: fix flake8 error
Browse files Browse the repository at this point in the history
  • Loading branch information
fedorov committed Oct 26, 2018
1 parent 3742735 commit 41000f5
Showing 1 changed file with 0 additions and 1 deletion.
1 change: 0 additions & 1 deletion labs/pyradiomics-dcm/pyradiomics-dcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ def addMeasurement(
return

def saveJSONToFile(self, fileName):
import json
with open(fileName, 'w') as f:
json.dump(self.m, f, indent=2, sort_keys=True)

Expand Down

7 comments on commit 41000f5

@fedorov
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JoostJM do you know why the errors on CI are not detected with flake8 run locally (from the root of the pyradiomics repo)?

[scikit-ci] Executing: flake8
./labs/pyradiomics-dcm/pyradiomics-dcm.py:220: [W605] invalid escape sequence '\d'
    elif re.match("log-sigma-([\d]+)-([\d]+)-([a-z]+)", prefix):
                 ^
./labs/pyradiomics-dcm/pyradiomics-dcm.py:220: [W605] invalid escape sequence '\d'
    elif re.match("log-sigma-([\d]+)-([\d]+)-([a-z]+)", prefix):
                         ^
./labs/pyradiomics-dcm/pyradiomics-dcm.py:221: [W605] invalid escape sequence '\d'
      match = re.match("log-sigma-([\d]+)-([\d]+)-([a-z]+)", prefix)
                   ^
./labs/pyradiomics-dcm/pyradiomics-dcm.py:221: [W605] invalid escape sequence '\d'
      match = re.match("log-sigma-([\d]+)-([\d]+)-([a-z]+)", prefix)
                           ^
./labs/pyradiomics-dcm/pyradiomics-dcm.py:290: [W504] line break after binary operator
        "Exception checking for NaN: " +
        ^
./labs/pyradiomics-dcm/pyradiomics-dcm.py:291: [W504] line break after binary operator
        str(e) +
        ^
./labs/pyradiomics-dcm/pyradiomics-dcm.py:292: [W504] line break after binary operator
        " " +
        ^
./labs/pyradiomics-dcm/pyradiomics-dcm.py:564: [W504] line break after binary operator
        dcm.SOPInstanceUID +
        ^
./radiomics/imageoperations.py:559: [W605] invalid escape sequence '\l'
  """
^
./radiomics/imageoperations.py:559: [W605] invalid escape sequence '\l'
  """
^
./radiomics/glcm.py:633: [W504] line break after binary operator
    Q = ((self.P_glcm[:, None, 0, :] * self.P_glcm[None, :, 0, :]) /  # slice: i, j, k, d
         ^
./radiomics/glcm.py:637: [W504] line break after binary operator
      Q += ((self.P_glcm[:, None, gl, :] * self.P_glcm[None, :, gl, :]) /  # slice: i, j, k, d
            ^
./radiomics/featureextractor.py:546: [W605] invalid escape sequence '\*'
    """
^
./radiomics/featureextractor.py:546: [W605] invalid escape sequence '\*'
    """

@JoostJM
Copy link
Collaborator

Choose a reason for hiding this comment

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

@fedorov, beats me. Did you run flake8 as flake8 .? Moreover, I can see that it is indeed failing on Linux and Windows, but not on macOS, which seems strange to me as wel. Let met checkout the latest master and take a look at it.

@fedorov
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did you run flake8 as flake8 .?

Yes - no issues on my mac with the current master!

@jcfr, since this involves scikit-ci - including you FYI.

@fedorov
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Further details - I tested locally with python 3.5.3.

@jcfr
Copy link
Collaborator

@jcfr jcfr commented on 41000f5 Oct 30, 2018

Choose a reason for hiding this comment

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

Since the dependencies are not installed with -U, I suspect there are cached and an older version of flake8 is used. See https://github.com/Radiomics/pyradiomics/blob/master/scikit-ci.yml#L36-L37

Two options to mitigate:

  • pin all dependencies in the requirements files
  • or use -U to install dependencies

@JoostJM
Copy link
Collaborator

Choose a reason for hiding this comment

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

@fedorov I reviewed the flake8 errors, and fixed it by adding 504 to the ignore list. It now passes the build. W504 is the line break, which we require to adhere to the max line length (in GLCM). Still, I updated the lines in your labs script to keep it more on a single line, using formatters and such)

As to the W605 warnings you were getting, they were entirely valid. The trick in python is that if you want to define a string which has escape characters, such as a pattern string for regex or a docstring with escapes for math, you need to specify the string as a raw-string (by prepending an r). Otherwise python tries to resolve the escapes (intended for e.g. adding a newline character in a single line string).

@fedorov
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! I did not investigate this since I could not reproduce the flake errors on my machine. As I mentioned earlier, there were no errors reported when I ran flake8 locally from the pyradiomics directory with the pyradiomics flake8 settings.

Please sign in to comment.