Skip to content

Commit

Permalink
pytest+flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
sergioburdisso committed Nov 11, 2019
1 parent 53a24bc commit 6b888e1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
35 changes: 17 additions & 18 deletions pyss3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def __trie_node__(self, ngram, icat):
for word in ngram[1:]:
word_info = word_info[NEXT][word]
return word_info
except:
except BaseException:
return EMPTY_WORD_INFO

def __get_category__(self, name):
Expand Down Expand Up @@ -681,11 +681,9 @@ def __update_max_gvs__(self, icat, vocab, preffix):

def __update_needed__(self):
"""Return True if an update is needed, false otherwise."""
return (
self.__s__ != self.__s_update__ or
self.__l__ != self.__l_update__ or
self.__p__ != self.__p_update__
)
return (self.__s__ != self.__s_update__ or
self.__l__ != self.__l_update__ or
self.__p__ != self.__p_update__)

def __save_cat_vocab__(self, icat, path, n_grams):
"""Save the category vocabulary inside ``path``."""
Expand Down Expand Up @@ -900,7 +898,7 @@ def get_word_index(self, word):
"""
try:
return self.__word_to_index__[word]
except:
except KeyError:
return None

def get_word(self, index):
Expand Down Expand Up @@ -1722,16 +1720,6 @@ def __init__(self, msg=''):
"The given category is not valid"
)

# aliases
SS3.set_smoothness = SS3.set_s
SS3.get_smoothness = SS3.get_s
SS3.set_significance = SS3.set_l
SS3.get_significance = SS3.get_l
SS3.set_sanction = SS3.set_p
SS3.get_sanction = SS3.get_p
SS3.set_alpha = SS3.set_a
SS3.get_alpha = SS3.get_a


def sigmoid(v, l):
"""A sigmoid function."""
Expand All @@ -1750,7 +1738,7 @@ def mad(values, n):
return (values[0], values[0])
values_m = n // 2 if n % 2 else n // 2 - 1
m = values[values_m] # Median
sd = sum([abs(m - lv) for lv in values]) / n # sd Mean
sd = sum([abs(m - lv) for lv in values]) / float(n) # sd Mean
return m, sd


Expand Down Expand Up @@ -1778,3 +1766,14 @@ def vmax(v0, v1):
def vdiv(v0, v1):
"""Vectorial version of division."""
return [v0[i] / v1[i] if v1[i] else 0 for i in xrange(len(v0))]


# aliases
SS3.set_smoothness = SS3.set_s
SS3.get_smoothness = SS3.get_s
SS3.set_significance = SS3.set_l
SS3.get_significance = SS3.get_l
SS3.set_sanction = SS3.set_p
SS3.get_sanction = SS3.get_p
SS3.set_alpha = SS3.set_a
SS3.get_alpha = SS3.get_a
21 changes: 11 additions & 10 deletions pyss3/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def parse_hparams_args(op_args, defaults=True):
hparams[hp_str] = round_fix(op_args[argi + 1])
except IndexError:
Print.error(ERROR_HVM % hp_str, raises=ArgsParseError)
except:
except BaseException:
Print.error(
ERROR_HIV % op_args[argi + 1], raises=ArgsParseError
)
Expand Down Expand Up @@ -902,7 +902,7 @@ def delete_results_slpa(rh_metric, hparams, only_count=False, best=True):
del values[s][l][p]

if not values[s][l]:
del values[s][l]
del values[s][l]

if not values[s]:
del values[s]
Expand Down Expand Up @@ -2214,7 +2214,7 @@ def args_train(self, args):
n_grams = int(n_grams_arg.group(1))
if n_grams <= 0:
raise Exception
except:
except BaseException:
Print.error(ERROR_WNGRAM, raises=ArgsParseError)

unkown_args = subtract(range(len(op_args)), op_args_ix)
Expand Down Expand Up @@ -2290,7 +2290,7 @@ def args_k_fold(self, args):
n_grams = int(n_grams_arg.group(1))
if n_grams <= 0:
raise Exception
except:
except BaseException:
Print.error(ERROR_WNGRAM, raises=ArgsParseError)

k_fold_arg = re_in(r"(.+)-" + STR_FOLD, op_args)
Expand All @@ -2301,7 +2301,7 @@ def args_k_fold(self, args):

if k_fold < 2:
raise Exception
except:
except BaseException:
Print.error(ERROR_WKFOLD, raises=ArgsParseError)

folder_arg = intersect([STR_FILE, STR_FOLDER], op_args)
Expand Down Expand Up @@ -2350,7 +2350,7 @@ def args_grid_search(self, args):
n_grams = int(n_grams_arg.group(1))
if n_grams <= 0:
raise Exception
except:
except BaseException:
Print.error(ERROR_WNGRAM, raises=ArgsParseError)

k_fold_arg = re_in(r"(.+)-" + STR_FOLD, op_args)
Expand All @@ -2361,7 +2361,7 @@ def args_grid_search(self, args):

if k_fold < 2:
raise Exception
except:
except BaseException:
Print.error(ERROR_WKFOLD, raises=ArgsParseError)

folder_arg = intersect([STR_FILE, STR_FOLDER], op_args)
Expand All @@ -2381,7 +2381,7 @@ def args_grid_search(self, args):
hparams[hp_str] = eval(op_args[argi + 1])
except IndexError:
Print.error(ERROR_HVM % hp_str, raises=ArgsParseError)
except:
except BaseException:
Print.error(
"[python] error: "
"the value for the hyper-parameter '%s' is not valid"
Expand All @@ -2392,7 +2392,7 @@ def args_grid_search(self, args):
# just in case the hyper-parameter value is a single number
try:
hparams[hp_str] = [float(hparams[hp_str])]
except:
except BaseException:
pass

try:
Expand Down Expand Up @@ -2538,7 +2538,7 @@ def args_learn(self, args):
n_grams = int(n_grams_arg.group(1))
if n_grams <= 0:
raise Exception
except:
except BaseException:
Print.error(ERROR_WNGRAM, raises=ArgsParseError)

def_cat_arg = subtract(range(len(op_args)), op_args_ix)
Expand Down Expand Up @@ -2668,5 +2668,6 @@ def main():
print("\nKeyboardInterrupt")
prompt.do_exit()


if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion pyss3/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# python 2 and 3 compatibility
try:
from urllib.parse import unquote as url_decode
except:
except ImportError:
from urllib import unquote as url_decode


Expand Down Expand Up @@ -451,6 +451,7 @@ def serve(
server_socket.close()
Server.__server_socket__ = None


if __name__ == "__main__":
parser = argparse.ArgumentParser(description='SS3 Server')

Expand Down
2 changes: 1 addition & 1 deletion pyss3/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def clean_and_ready(text, dots=True, normalize=True, min_len=1):
if normalize:
try:
text = text.decode("utf-8")
except:
except BaseException:
pass

text = ''.join(
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[flake8]
max-line-length = 100
ignore = E741

0 comments on commit 6b888e1

Please sign in to comment.