-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Refactor by pep8 #1550
Refactor by pep8 #1550
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome changes overall, thanks! Minor fixes required, see comments.
from .textcorpus import TextCorpus | ||
from .ucicorpus import UciCorpus | ||
from .malletcorpus import MalletCorpus | ||
from .mmcorpus import MmCorpus # noqa:F401 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1: we don't want to litter the code with some tool-specific constructs.
Instead, open an issue with the tool that requires this, it's a bug on their side if they cannot handle this line.
If you find such comments in other parts of gensim, please remove them too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piskvorky it's not a tool bug, it's really "unused import" by PEP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it is used -- it makes the classes available directly from the package. Without it, you won't be able to from corpora import MmCorpus
.
Or how can this be done in other way, that doesn't trigger F401?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it makes the classes available directly from the package
You are right, but now in the code, it's unused import.
I know another way - use this imports (like your example) in gensim internally, but I don't think that this is a good idea. For my opinion, noqa
suppress is OK.
gensim/examples/dmlcz/sources.py
Outdated
def idFromDir(self, path): | ||
assert len(path) > len(self.baseDir) | ||
dmlczId = open(os.path.join(path, 'dspace_id')).read().strip() | ||
pathId = path[len(self.baseDir) + 1 : ] | ||
pathId = path[len(self.baseDir) + 1:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is against PEP8 (see https://www.python.org/dev/peps/pep-0008/#other-recommendations ).
gensim/interfaces.py
Outdated
@@ -267,7 +263,7 @@ def __iter__(self): | |||
# (unlike numpy). so, clip the end of the chunk explicitly to make | |||
# scipy.sparse happy | |||
chunk_end = min(self.index.shape[0], chunk_start + self.chunksize) | |||
chunk = self.index[chunk_start : chunk_end] | |||
chunk = self.index[chunk_start: chunk_end] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8: https://www.python.org/dev/peps/pep-0008/#other-recommendations (here and elsewhere).
For example
E722 error occurs except line In gensim code, some line add Exception class but the others not specify exception So if not used exception class in exception scope, I just add Exception like under code
|
I miss check in corpora dir files. I'm not touch about noqa, line slice whitespace yet. and naming like 'l' changed to suitable name |
gensim/matutils.py
Outdated
@@ -150,7 +150,7 @@ def zeros_aligned(shape, dtype, order='C', align=128): | |||
nbytes = np.prod(shape, dtype=np.int64) * np.dtype(dtype).itemsize | |||
buffer = np.zeros(nbytes + align, dtype=np.uint8) # problematic on win64 ("maximum allowed dimension exceeded") | |||
start_index = -buffer.ctypes.data % align | |||
return buffer[start_index: start_index + nbytes].view(dtype).reshape(shape, order=order) | |||
return buffer[start_index:start_index + nbytes].view(dtype).reshape(shape, order=order) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not conform to PEP8 (need spaces around :
here, see #1521 (comment)).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piskvorky Sorry, Line slice white space was not my intention. I missed these line in this commit.
Anyway, I agree to input space around :
.
but if input space like return buffer[start_index : start_index + nbytes]
, E203 error occurs. (pycodestyle issue)
Is the above line okay if an error occurs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's any error in the code, the version with spaces is correct. The version without spaces is incorrect. It appears to be a bug in the style-checking software. CC @menshikh-iv
Issue #1551
I have adding above comment ignore file It may be dangerous but I think Excepts models/_init.py, this file contains short class. |
gensim/corpora/__init__.py
Outdated
@@ -1,17 +1,17 @@ | |||
""" | |||
This package contains implementations of various streaming corpus I/O format. | |||
""" | |||
|
|||
# flake8: noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to combine the worst of both worlds. Still extra comments, AND no style checking.
I think I prefer even the noqa:F401
version.
7a5dd56
to
22816c0
Compare
@piskvorky I canceled commit about ignore whole file.
And just |
Sorry, I clicked delete accidently. And I think I've finished applying PEP8.
|
Hi @zsef123, please remove file gensim/scripts/make_wiki_lemma.py from your PR ASAP (because you broke current symlink -> we can't build package) |
@zsef123 I means to remove this file from your PR (not from the repo), you need to checkout this file to |
@menshikh-iv Sorry I check again.
Issue #1521
And
So I input space around |
@zsef123 space before |
@menshikh-iv In matutils.py, I already remove space before
So I changed to input space around |
b0f77a8
to
8240c7d
Compare
@menshikh-iv Should I remove space before |
@zsef123 yep |
Very large and useful work, thank you very much @zsef123 🔥 |
…orky#1550) * gensim dir PEP8 fixes * corpora dir PEP8 fixes * example dir PEP8 fixes * model/wrapper dir PEP8 fixes * models dir PEP8 fixes * parsing dir PEP8 fixes * scripts dir PEP8 fixes * similarities dir PEP8 fixes * summarization and topic_coherence dir PEP8 fixes * test dir PEP8 fixes * PEP8 E722 error fixes * PEP8 fixes * list slice whitespace PEP8 fixes * disassemble import * * Fix symlink * fix symlink * fix make_wiki_lemma file * Replace relative import to absolute * fix typo * fix E203 error
Fixes #1521
First checkbox
Most changes are whitespace adjustment and import order changes.
Then unused var and header are removed except in try catch, named _ var and side effects call.
Excepted case add comments 'noqa'
And test_atmodel.py, test_ldamallet_wrapper.py, test_ldamodel codes don't use fname like under code
save or load argument changed from testfile() to fname