Skip to content
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

Fixing depracation warning: time.clock(); collections.Iterable #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions flexp/flow/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def _get_chain_mtime(self, chain):
"""
chain_mtimes = [0.] # default time in case no other time is obtained
for module in chain:
if isinstance(module, collections.Iterable): # module is a chain
if isinstance(module, collections.abc.Iterable): # module is a chain
chain_mtimes.append(self._get_chain_mtime(module))
elif hasattr(module, 'process'): # module is an object
chain_mtimes.append(self._get_object_mtime(module))
Expand All @@ -254,7 +254,7 @@ def _get_chain_repr(self, chain):
"""
chain_repr = []
for module in chain:
if isinstance(module, collections.Iterable): # module is a chain
if isinstance(module, collections.abc.Iterable): # module is a chain
chain_repr.append(self._get_chain_repr(module))
elif hasattr(module, 'process'): # module is an object
chain_repr.extend(
Expand Down
6 changes: 3 additions & 3 deletions flexp/flow/caching_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import hashlib
import os
import time
import timeit

from flexp.flow import Chain
from flexp.flow.cache import PickleCache, ObjectDumper
Expand Down Expand Up @@ -109,11 +109,11 @@ def process(self, data):
else:
log.debug("{}()".format(self.names[i]))
process_func = self.modules[i]
start = time.clock()
start = timeit.default_timer()
# update data ket from list before running module
setattr(data, self.update_data_id, updated_ids[i])
process_func(data)
end = time.clock()
end = timeit.default_timer()
self.times[i] += (end - start)
except StopIteration:
log.debug("{} requested stop. Processing stopped".format(
Expand Down
8 changes: 4 additions & 4 deletions flexp/flow/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import division

import collections
import time
import timeit
import types

from flexp.utils import get_logger
Expand Down Expand Up @@ -67,7 +67,7 @@ def add(self, module):
"""
if not module:
return
if isinstance(module, collections.Iterable):
if isinstance(module, collections.abc.Iterable):
for m in module:
self._add(m)
else:
Expand Down Expand Up @@ -120,9 +120,9 @@ def process(self, data):
else:
log.debug("{}()".format(self.names[i]))
process_func = self.modules[i]
start = time.clock()
start = timeit.default_timer()
process_func(data)
end = time.clock()
end = timeit.default_timer()
self.times[i] += (end - start)
except StopIteration:
log.debug("{} requested stop. Processing stopped".format(
Expand Down
8 changes: 4 additions & 4 deletions tests/test_cache_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from flexp.flow import cache


class TestModule:
class DummyModule:

PickleCacheBlackList = ['attr3']

Expand Down Expand Up @@ -37,20 +37,20 @@ def tearDown(self):
def test_cache(self):

c = cache.PickleCache(self.cache_dir, "input", chain=[
TestModule(12, 14, 18),
DummyModule(12, 14, 18),
])
c.process({"input": 10})

# different value for attribute from black list
c2 = cache.PickleCache(self.cache_dir, "input", chain=[
TestModule(12, 14, 20),
DummyModule(12, 14, 20),
])
c2.process({"input": 10})
self.assertEqual(c.chain_info['chain_hash'], c2.chain_info['chain_hash'])

# different value for attribute that is not in black list
c3 = cache.PickleCache(self.cache_dir, "input", chain=[
TestModule(12, 12, 18),
DummyModule(12, 12, 18),
])
c3.process({"input": 10})
self.assertFalse(c.chain_info['chain_hash'] == c3.chain_info['chain_hash'])
Expand Down
2 changes: 0 additions & 2 deletions tests/test_flexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import atexit
import io
import os
import time
from os import path
import shutil
from pprint import pprint

import pytest

Expand Down
9 changes: 6 additions & 3 deletions tests/test_parallel.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import print_function

import time
import timeit
import unittest


from flexp.flow.parallel import parallelize


Expand All @@ -16,9 +17,11 @@ def test_parallel(self):
count = 50
data = range(0, count)

start = time.clock()
start = timeit.default_timer()
res = list(parallelize(add_two, data, 25))
end = time.clock()
end = timeit.default_timer()

print("Time to process {}".format(end - start))

assert len(res) == count
assert sum(res) == (2 + count + 1) * count / 2