-
Notifications
You must be signed in to change notification settings - Fork 627
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
Fix Python formatting #3962
Fix Python formatting #3962
Conversation
!build |
CI MESSAGE: [5025731]: BUILD STARTED |
CI MESSAGE: [5025731]: BUILD FAILED |
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.
Please consider wrapping the function parameters differently. I've posted handful of suggestions, at some point I stopped posting them though ;)
What I'm referring to is such example:
class PreemphasisPythonPipeline(Pipeline):
def __init__(self,
device,
batch_size,
iterator,
border='clamp',
preemph_coeff=0.97,
per_sample_coeff=False,
num_threads=4,
device_id=0):
super(PreemphasisPythonPipeline, self).__init__(batch_size,
num_threads,
device_id,
seed=SEED,
exec_async=False,
exec_pipelined=False)
->
class PreemphasisPythonPipeline(Pipeline):
def __init__(self, device, batch_size, iterator, border='clamp', preemph_coeff=0.97,
per_sample_coeff=False, num_threads=4, device_id=0):
super().__init__(batch_size, num_threads, device_id, seed=SEED, exec_async=False,
exec_pipelined=False)
or
def check_transform_shear_op(shear=None,
angles=None,
center=None,
has_input=False,
reverse_order=False,
batch_size=1,
num_threads=4,
device_id=0):
->
def check_transform_shear_op(shear=None, angles=None, center=None, has_input=False,
reverse_order=False, batch_size=1, num_threads=4, device_id=0):
Anyway, that's your call. I don't see any blockers. I've put some suggestions, feel free to reject them, if you feel these aren't necessary.
def __init__(self, | ||
device, | ||
batch_size, | ||
iterator, | ||
border='clamp', | ||
preemph_coeff=0.97, | ||
per_sample_coeff=False, | ||
num_threads=4, | ||
device_id=0): | ||
super(PreemphasisPythonPipeline, self).__init__(batch_size, | ||
num_threads, | ||
device_id, | ||
seed=SEED, | ||
exec_async=False, | ||
exec_pipelined=False) |
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.
How about?
class PreemphasisPythonPipeline(Pipeline):
def __init__(self, device, batch_size, iterator, border='clamp', preemph_coeff=0.97,
per_sample_coeff=False, num_threads=4, device_id=0):
super().__init__(batch_size, num_threads, device_id, seed=SEED, exec_async=False,
exec_pipelined=False)
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.
Turned a knob in yapf so the formatting is more condensed. I also reverted the changes where not needed as apparently we don't want to have that.
|
||
def shape_gen_fn(): | ||
return random_shape(in_shape_min, in_shape_max, ndim) | ||
|
||
def data_gen_f(): | ||
return batch_gen(max_batch_size, shape_gen_fn) | ||
|
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.
In the named lambdas case (we have handful of that) I like what @jantonguirao proposed:
def shape_gen_fn(): return random_shape(in_shape_min, in_shape_max, ndim)
def data_gen_f(): return batch_gen(max_batch_size, shape_gen_fn)
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 would be in favor of keeping regular function line breaks. We are just defining them, not passing something inline
yield raises( | ||
RuntimeError, | ||
glob=error_msg)(check_fail_sequence_rearrange), 2, shape, new_order, per_sample, dev |
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.
Leaving aside, that yield raises(...)(...)
looks really peculiar, how about this kind of formatting?
yield raises(RuntimeError, glob=error_msg)(check_fail_sequence_rearrange), \
2, shape, new_order, per_sample, dev
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 made it consistent with the one below that is so long, that it had to be broken similar way.
np.testing.assert_array_equal(out, | ||
op(l_np, r_np), | ||
err_msg="{} op\n{} =\n{}".format(l_np, r_np, out)) |
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.
How about using modern f
notation? This way this can be squashed into one line:
np.testing.assert_array_equal(out, | |
op(l_np, r_np), | |
err_msg="{} op\n{} =\n{}".format(l_np, r_np, out)) | |
np.testing.assert_array_equal(out, op(l_np, r_np), err_msg=f"{l_np} op\n{r_np} =\n{out}") |
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.
done
pipe = ExprOpPipeline(kinds, | ||
types, | ||
iterator, (lambda x, y: x // y), | ||
batch_size=batch_size, | ||
num_threads=2, | ||
device_id=0) |
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 believe this looks odd. I'm OK with putting every argument in a separate line, but if so, I'd vote for not putting two args in one line by exception, i.e.
pipe = ExprOpPipeline(kinds,
types,
iterator, (lambda x, y: x // y), <--- here
batch_size=batch_size,
num_threads=2,
device_id=0)
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.
Hmm, I will try some knobs to see why it happened.
def check_raises_te(kinds, types, op, shape, _): | ||
check_raises(kinds, types, op, shape) | ||
|
||
|
||
# Arithmetic operations between booleans that are not allowed | ||
bool_disallowed = [((lambda x, y: x + y), "+"), ((lambda x, y: x - y), "-"), | ||
((lambda x, y: x / y), "/"), ((lambda x, y: x / y), "//"), | ||
((lambda x, y: x ** y), "**")] | ||
((lambda x, y: x**y), "**")] |
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.
TIL that pow
operator formatting in Python w.r.t. whitespace is inconsistent with other ops :D
import os | ||
from glob import glob | ||
import math | ||
import dali |
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.
import dali | |
import nvidia.dali as dali |
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.
done
assert val == expected_val, ( | ||
f"Unexpected value in batch: got {val}, expected {expected_val}, " | ||
f"for batch {batch_idx}, sample {idx_in_batch}") |
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.
Is this parenthesis required for anything?
assert val == expected_val, ( | |
f"Unexpected value in batch: got {val}, expected {expected_val}, " | |
f"for batch {batch_idx}, sample {idx_in_batch}") | |
assert val == expected_val, \ | |
f"Unexpected value in batch: got {val}, expected {expected_val}, " \ | |
f"for batch {batch_idx}, sample {idx_in_batch}" |
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.
To not use the \
I'd say it's preferred.
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 says so, I guess, but it still looks no less weird than a backslash (and perhaps more so).
integer_types = [ | ||
np.bool_, np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16, np.uint32, np.uint64 | ||
] |
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.
and the nice grouping went to Hell... - I think the original formatting was actually correct under PEP8?
pipe = ExprOpPipeline(kind, type, iterator, op, batch_size=batch_size, num_threads=2, | ||
device_id=0) | ||
device_id=0) |
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.
pipe = ExprOpPipeline(kind, type, iterator, op, batch_size=batch_size, num_threads=2, | |
device_id=0) | |
device_id=0) | |
pipe = ExprOpPipeline(kind, type, iterator, op, | |
batch_size=batch_size, num_threads=2, device_id=0) |
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'd like this file compatible with full auto-format and this doesn't work.
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.
pipe = ExprOpPipeline(kind, type, iterator, op, batch_size=batch_size, num_threads=2, | |
device_id=0) | |
device_id=0) | |
pipe = ExprOpPipeline( | |
kind, type, iterator, op, batch_size=batch_size, num_threads=2, device_id=0) |
Out of curiosity: would this work?
!build |
for types_in in [(np.int32, np.int32, np.int32), (np.float32, np.int32, np.int32), | ||
(np.uint8, np.float32, np.float32), (np.int32, np.float32, np.float32)]: | ||
(np.uint8, np.float32, np.float32), | ||
(np.int32, np.float32, np.float32)]: |
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.
for types_in in [(np.int32, np.int32, np.int32), (np.float32, np.int32, np.int32), | |
(np.uint8, np.float32, np.float32), (np.int32, np.float32, np.float32)]: | |
(np.uint8, np.float32, np.float32), | |
(np.int32, np.float32, np.float32)]: | |
for types_in in [(np.int32, np.int32, np.int32), | |
(np.float32, np.int32, np.int32), | |
(np.uint8, np.float32, np.float32), | |
(np.int32, np.float32, np.float32)]: |
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.
done
pipe = ExprOpPipeline(kinds, types, iterator, op, batch_size=batch_size, num_threads=2, | ||
device_id=0) | ||
device_id=0) |
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.
pipe = ExprOpPipeline(kinds, types, iterator, op, batch_size=batch_size, num_threads=2, | |
device_id=0) | |
device_id=0) | |
pipe = ExprOpPipeline(kinds, types, iterator, op, | |
batch_size=batch_size, num_threads=2, device_id=0) |
pipe = ExprOpPipeline(kinds, types, iterator, dali_op, batch_size=batch_size, num_threads=2, | ||
device_id=0) |
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.
pipe = ExprOpPipeline(kinds, types, iterator, dali_op, batch_size=batch_size, num_threads=2, | |
device_id=0) | |
pipe = ExprOpPipeline(kinds, types, iterator, dali_op, | |
batch_size=batch_size, num_threads=2, device_id=0) |
pipe = ExprOpPipeline(kinds, types, iterator, (lambda x, y: x // y), batch_size=batch_size, | ||
num_threads=2, device_id=0) |
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.
pipe = ExprOpPipeline(kinds, types, iterator, (lambda x, y: x // y), batch_size=batch_size, | |
num_threads=2, device_id=0) | |
pipe = ExprOpPipeline(kinds, types, iterator, (lambda x, y: x // y), | |
batch_size=batch_size, num_threads=2, device_id=0) |
yield check_raises_re, kinds, (np.bool_, np.bool_, | ||
np.bool_), op, shape_small, op_desc, error_msg |
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.
Please.... this is just a coincidence - don't abuse it.
yield check_raises_re, kinds, (np.bool_, np.bool_, | |
np.bool_), op, shape_small, op_desc, error_msg | |
yield check_raises_re, kinds, (np.bool_, np.bool_, np.bool_), \ | |
op, shape_small, op_desc, error_msg |
or
yield check_raises_re, kinds, (np.bool_, np.bool_, | |
np.bool_), op, shape_small, op_desc, error_msg | |
yield (check_raises_re, kinds, (np.bool_, np.bool_, np.bool_), | |
op, shape_small, op_desc, error_msg) |
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.
done
CI MESSAGE: [5034722]: BUILD STARTED |
), | ||
) | ||
) | ||
lambda s: int(s[s.rfind("/") + 1:s.rfind(".")]) < 2500, |
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 less readable; the colon disappeared.
lambda s: int(s[s.rfind("/") + 1:s.rfind(".")]) < 2500, | |
lambda s: int(s[s.rfind("/") + 1 : s.rfind(".")]) < 2500, |
According to PEP8, the colon in array slice can have spaces on both sides or none.
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.
According to my flake8 it's not allowed, just tried it, reverting.
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's a known bug in flake8.... known since 2015.... to make it even "funnier", black adds those spaces and doesn't have an option not to 🙃
I think we should disable E203 entirely in flake8 - can we do it?
Related issues:
PyCQA/flake8#257
PyCQA/pycodestyle#373
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.
Dunno. Sadly, it's not possible to use black with our codebase, so this is what we get with flake8 and other formatters, which is still pep8 compliant (as it has uniform spacing).
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.
Then:
lambda s: int(s[s.rfind("/") + 1:s.rfind(".")]) < 2500, | |
lambda s: int(s[s.rfind("/") + 1 : s.rfind(".")]) < 2500, # noqa: 203 |
?
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 know if that's much better with the noqa, but done.
dali/test/python/test_operator_readers_webdataset_requirements.py
Outdated
Show resolved
Hide resolved
dali/test/python/test_operator_readers_webdataset_requirements.py
Outdated
Show resolved
Hide resolved
dali/test/python/test_operator_readers_webdataset_requirements.py
Outdated
Show resolved
Hide resolved
Signed-off-by: Krzysztof Lecki <[email protected]>
Signed-off-by: Krzysztof Lecki <[email protected]>
Signed-off-by: Krzysztof Lecki <[email protected]>
Signed-off-by: Krzysztof Lecki <[email protected]>
Signed-off-by: Krzysztof Lecki <[email protected]>
Signed-off-by: Krzysztof Lecki <[email protected]>
Signed-off-by: Krzysztof Lecki <[email protected]>
Signed-off-by: Krzysztof Lecki <[email protected]>
Signed-off-by: Krzysztof Lecki <[email protected]>
Signed-off-by: Krzysztof Lecki <[email protected]>
Signed-off-by: Krzysztof Lecki <[email protected]>
Co-authored-by: Michał Zientkiewicz <[email protected]>
Co-authored-by: Michał Zientkiewicz <[email protected]>
This reverts commit a6fda0d.
Signed-off-by: Krzysztof Lecki <[email protected]>
Signed-off-by: Krzysztof Lecki <[email protected]>
Signed-off-by: Krzysztof Lecki <[email protected]>
Signed-off-by: Krzysztof Lecki <[email protected]>
Signed-off-by: Krzysztof Lecki <[email protected]>
Signed-off-by: Krzysztof Lecki <[email protected]>
11633e6
to
cf9dd80
Compare
!build |
CI MESSAGE: [5045456]: BUILD FAILED |
!build |
CI MESSAGE: [5045665]: BUILD STARTED |
CI MESSAGE: [5045665]: BUILD FAILED |
CI MESSAGE: [5045665]: BUILD PASSED |
Category: Other
Description:
Conformance to pep8 was achieved by running
yapf and adjusting by hand the rest of issues
reported by flake8.
Additional information:
Affected modules and functionalities:
Key points relevant for the review:
Tests:
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: N/A