Skip to content

Commit

Permalink
replace has_key by in (apache#8317)
Browse files Browse the repository at this point in the history
* replace `has_key` by `in`

* Update utils.py
  • Loading branch information
chihming authored and piiswrong committed Nov 19, 2017
1 parent 54df0e5 commit 4f56de6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/mxnet/notebook/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def _process_batch(self, param, df_name):
metrics = {}
metrics['elapsed'] = datetime.datetime.now() - self.start_time
for key, value in metrics.items():
if not self._data[df_name].has_key(key):
if key not in self._data[df_name]:
self._data[df_name][key] = []
self._data[df_name][key].append(value)

Expand Down
2 changes: 1 addition & 1 deletion tests/nightly/TestDoc/doc_spell_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def check_doc(file_content, spell_checker, spell_check_ret):
"""
spell_checker.set_text(file_content)
for error in spell_checker:
if spell_check_ret.has_key(error.word):
if error.word in spell_check_ret:
spell_check_ret[error.word] += 1
else:
spell_check_ret[error.word] = 1
Expand Down
2 changes: 1 addition & 1 deletion tools/accnn/rank_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get_ranksel(model, ratio):
if nxt_c > EC:
continue
nxt_v = dp[now][now_c] + math.log(S[i][d])
if dp[nxt].has_key(nxt_c):
if nxt_c in dp[nxt]:
if nxt_v > dp[nxt][nxt_c]:
dp[nxt][nxt_c] = nxt_v
dpc[i][nxt_c] = (d,now_c)
Expand Down
5 changes: 3 additions & 2 deletions tools/accnn/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import json
import ast


def load_model(args):
devs = mx.cpu() if args.gpus == None else [mx.gpu(int(i)) for i in args.gpus.split(',')]
return mx.model.FeedForward.load(args.model, args.load_epoch, ctx=devs)
Expand All @@ -29,7 +30,7 @@ def topsort(nodes):
deg = [0]*n
g = [[] for _ in xrange(n)]
for i,node in enumerate(nodes):
if node.has_key('inputs'):
if 'inputs' in node:
for j in node['inputs']:
deg[i] += 1
g[j[0]].append(i)
Expand All @@ -45,7 +46,7 @@ def topsort(nodes):
q.append(j)
new_ids=dict([(node['name'],i) for i,node in enumerate(res)])
for node in res:
if node.has_key('inputs'):
if 'inputs' in node:
for j in node['inputs']:
j[0]=new_ids[nodes[j[0]]['name']]
return res
Expand Down

0 comments on commit 4f56de6

Please sign in to comment.