Skip to content

Commit

Permalink
Update PyLint and Flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
freud14 committed Nov 5, 2022
1 parent 1d9b5fb commit 7f6a358
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 89 deletions.
76 changes: 1 addition & 75 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,81 +54,14 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=print-statement,
parameter-unpacking,
unpacking-in-except,
old-raise-syntax,
backtick,
long-suffix,
old-ne-operator,
old-octal-literal,
import-star-module-level,
non-ascii-bytes-literal,
raw-checker-failed,
disable=raw-checker-failed,
bad-inline-option,
locally-disabled,
locally-enabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
apply-builtin,
basestring-builtin,
buffer-builtin,
cmp-builtin,
coerce-builtin,
execfile-builtin,
file-builtin,
long-builtin,
raw_input-builtin,
reduce-builtin,
standarderror-builtin,
unicode-builtin,
xrange-builtin,
coerce-method,
delslice-method,
getslice-method,
setslice-method,
no-absolute-import,
old-division,
dict-iter-method,
dict-view-method,
next-method-called,
metaclass-assignment,
indexing-exception,
raising-string,
reload-builtin,
oct-method,
hex-method,
nonzero-method,
cmp-method,
input-builtin,
round-builtin,
intern-builtin,
unichr-builtin,
map-builtin-not-iterating,
zip-builtin-not-iterating,
range-builtin-not-iterating,
filter-builtin-not-iterating,
using-cmp-argument,
eq-without-hash,
div-method,
idiv-method,
rdiv-method,
exception-message-attribute,
invalid-str-codec,
sys-max-int,
bad-python3-import,
deprecated-string-function,
deprecated-str-translate-call,
deprecated-itertools-function,
deprecated-types-field,
next-method-defined,
dict-items-not-iterating,
dict-keys-not-iterating,
dict-values-not-iterating,
invalid-name,
no-self-use,
missing-docstring,
len-as-condition,
attribute-defined-outside-init,
Expand Down Expand Up @@ -241,13 +174,6 @@ max-line-length=120
# Maximum number of lines in a module
max-module-lines=1000

# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
# `empty-line` allows space-only lines.
no-space-check=trailing-comma,
dict-separator

# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
single-line-class-stmt=no
Expand Down
4 changes: 3 additions & 1 deletion poutyne/framework/metrics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def get_names_of_metric(metric):


def flatten_metric_names(metric_names):
to_list = lambda names: names if isinstance(names, (tuple, list)) else [names]
def to_list(names):
return names if isinstance(names, (tuple, list)) else [names]

return [name for names in metric_names for name in to_list(names)]


Expand Down
10 changes: 8 additions & 2 deletions poutyne/framework/model_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,16 @@ def get_saved_epochs(self):
history = self.get_stats()
metrics = history[self.monitor_metric].tolist()
if self.monitor_mode == 'min':
monitor_op = lambda x, y: x < y

def monitor_op(x, y):
return x < y

current_best = float('Inf')
elif self.monitor_mode == 'max':
monitor_op = lambda x, y: x > y

def monitor_op(x, y):
return x > y

current_best = -float('Inf')
saved_epoch_indices = []
for i, metric in enumerate(metrics):
Expand Down
20 changes: 16 additions & 4 deletions poutyne/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,15 @@ def torch_to_numpy(obj, copy=False):
:meth:`~poutyne.torch_apply` for supported types.
"""
if copy:
func = lambda t: t.detach().cpu().numpy().copy()

def func(t):
return t.detach().cpu().numpy().copy()

else:
func = lambda t: t.detach().cpu().numpy()

def func(t):
return t.detach().cpu().numpy()

return torch_apply(obj, func)


Expand All @@ -88,7 +94,10 @@ def torch_apply(obj, func):
A new Python object with the same structure as `obj` but where the tensors have been applied
the function `func`. Not supported type are left as reference in the new object.
"""
fn = lambda t: func(t) if torch.is_tensor(t) else t

def fn(t):
return func(t) if torch.is_tensor(t) else t

return _apply(obj, fn)


Expand Down Expand Up @@ -148,7 +157,10 @@ def numpy_to_torch(obj):
"""
fn = lambda a: torch.from_numpy(a) if isinstance(a, np.ndarray) else a

def fn(a):
return torch.from_numpy(a) if isinstance(a, np.ndarray) else a

return _apply(obj, fn)


Expand Down
7 changes: 4 additions & 3 deletions styling_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
black~=22.3
astroid==2.12.12
black[jupyter]
pylint==2.12.1
flake8==4.0.1
black~=22.3
flake8==5.0.4
pylint==2.15.5
4 changes: 3 additions & 1 deletion tests/framework/callbacks/test_lr_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def setUp(self):
self.valid_gen = some_data_generator(20)

def test_lambda_lr_integration(self):
my_lambda = lambda epoch: 0.95**epoch
def my_lambda(epoch):
return 0.95**epoch

lambda_lr = LambdaLR(lr_lambda=[my_lambda])
self._fit_with_callback_integration(lambda_lr)

Expand Down
4 changes: 3 additions & 1 deletion tests/framework/callbacks/test_periodic.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ def test_restore_use_lambda_function(self):
a_function_mock = MagicMock()

a_restore_mock_function = MagicMock()
a_restore_function = lambda x: a_restore_mock_function(2)

def a_restore_function(_):
return a_restore_mock_function(2)

periodic_save_lambda = PeriodicSaveLambda(
filename=self.a_filename, func=a_function_mock, restore=a_restore_function
Expand Down
4 changes: 2 additions & 2 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def test_compare_plot_history_plot_metric(self):
def test_all_different(self):
plot_history_figs, _ = plot_history(PlotHistoryTest.HISTORY, close=False, show=False)
images = list(map(self._to_image, plot_history_figs))
for i, _ in enumerate(images):
for i, image_i in enumerate(images):
for j in range(i + 1, len(images)):
self.assertNotEqual(images[i], images[j])
self.assertNotEqual(image_i, images[j])

def test_title(self):
title = 'My Title'
Expand Down

0 comments on commit 7f6a358

Please sign in to comment.