mirror of
https://github.com/wassname/ray.git
synced 2026-06-29 09:22:57 +08:00
Clean up syntax for supported Python versions. (#1963)
* Use set/dict literal syntax Ran code through [pyupgrade](https://github.com/asottile/pyupgrade). This is supported in every Python version 2.7+. * Drop unnecessary string format specification No need to specify 0,1.. if paramters are passed in order. * Revert "Drop unnecessary string format specification" This reverts commit efa5ec85d30ff69f34e5ed93e31343fea7647bcb. * Undo changes to cloudpickle Drop use of set literal until cloudpickle uses it. * Reformat code with YAPF We need to set up a git pre-push hook to automatically run this stuff.
This commit is contained in:
committed by
Philipp Moritz
parent
d85ee0bc04
commit
cdf94c18a4
@@ -133,7 +133,7 @@ class TestObjectID(unittest.TestCase):
|
||||
x = random_object_id()
|
||||
y = random_object_id()
|
||||
{x: y}
|
||||
set([x, y])
|
||||
{x, y}
|
||||
|
||||
|
||||
class TestTask(unittest.TestCase):
|
||||
|
||||
@@ -106,7 +106,7 @@ class DataFrameGroupBy(object):
|
||||
|
||||
@property
|
||||
def groups(self):
|
||||
return dict([(k, pd.Index(v)) for k, v in self._keys_and_values])
|
||||
return {k: pd.Index(v) for k, v in self._keys_and_values}
|
||||
|
||||
def min(self, **kwargs):
|
||||
return self._apply_agg_function(lambda df: df.min(**kwargs))
|
||||
|
||||
@@ -49,7 +49,7 @@ class TensorFlowVariables(object):
|
||||
self.sess = sess
|
||||
queue = deque([loss])
|
||||
variable_names = []
|
||||
explored_inputs = set([loss])
|
||||
explored_inputs = {loss}
|
||||
|
||||
# We do a BFS on the dependency graph of the input function to find
|
||||
# the variables.
|
||||
|
||||
@@ -297,7 +297,7 @@ class TestPlasmaManager(unittest.TestCase):
|
||||
self.client1.seal(obj_id1)
|
||||
ready, waiting = self.client1.wait(
|
||||
[obj_id1], timeout=100, num_returns=1)
|
||||
self.assertEqual(set(ready), set([obj_id1]))
|
||||
self.assertEqual(set(ready), {obj_id1})
|
||||
self.assertEqual(waiting, [])
|
||||
|
||||
# Test wait if only one object available and only one object waited
|
||||
@@ -307,8 +307,8 @@ class TestPlasmaManager(unittest.TestCase):
|
||||
# Don't seal.
|
||||
ready, waiting = self.client1.wait(
|
||||
[obj_id2, obj_id1], timeout=100, num_returns=1)
|
||||
self.assertEqual(set(ready), set([obj_id1]))
|
||||
self.assertEqual(set(waiting), set([obj_id2]))
|
||||
self.assertEqual(set(ready), {obj_id1})
|
||||
self.assertEqual(set(waiting), {obj_id2})
|
||||
|
||||
# Test wait if object is sealed later.
|
||||
obj_id3 = random_object_id()
|
||||
@@ -321,14 +321,14 @@ class TestPlasmaManager(unittest.TestCase):
|
||||
t.start()
|
||||
ready, waiting = self.client1.wait(
|
||||
[obj_id3, obj_id2, obj_id1], timeout=1000, num_returns=2)
|
||||
self.assertEqual(set(ready), set([obj_id1, obj_id3]))
|
||||
self.assertEqual(set(waiting), set([obj_id2]))
|
||||
self.assertEqual(set(ready), {obj_id1, obj_id3})
|
||||
self.assertEqual(set(waiting), {obj_id2})
|
||||
|
||||
# Test if the appropriate number of objects is shown if some objects
|
||||
# are not ready.
|
||||
ready, waiting = self.client1.wait([obj_id3, obj_id2, obj_id1], 100, 3)
|
||||
self.assertEqual(set(ready), set([obj_id1, obj_id3]))
|
||||
self.assertEqual(set(waiting), set([obj_id2]))
|
||||
self.assertEqual(set(ready), {obj_id1, obj_id3})
|
||||
self.assertEqual(set(waiting), {obj_id2})
|
||||
|
||||
# Don't forget to seal obj_id2.
|
||||
self.client1.seal(obj_id2)
|
||||
|
||||
@@ -688,36 +688,36 @@ class PopulationBasedTestingSuite(unittest.TestCase):
|
||||
# Categorical case
|
||||
assertProduces(
|
||||
lambda: explore({"v": 4}, {"v": [3, 4, 8, 10]}, 0.0, lambda x: x),
|
||||
set([3, 8]))
|
||||
{3, 8})
|
||||
assertProduces(
|
||||
lambda: explore({"v": 3}, {"v": [3, 4, 8, 10]}, 0.0, lambda x: x),
|
||||
set([3, 4]))
|
||||
{3, 4})
|
||||
assertProduces(
|
||||
lambda: explore({"v": 10}, {"v": [3, 4, 8, 10]}, 0.0, lambda x: x),
|
||||
set([8, 10]))
|
||||
{8, 10})
|
||||
assertProduces(
|
||||
lambda: explore({"v": 7}, {"v": [3, 4, 8, 10]}, 0.0, lambda x: x),
|
||||
set([3, 4, 8, 10]))
|
||||
{3, 4, 8, 10})
|
||||
assertProduces(
|
||||
lambda: explore({"v": 4}, {"v": [3, 4, 8, 10]}, 1.0, lambda x: x),
|
||||
set([3, 4, 8, 10]))
|
||||
{3, 4, 8, 10})
|
||||
|
||||
# Continuous case
|
||||
assertProduces(
|
||||
lambda: explore(
|
||||
{"v": 100}, {"v": lambda: random.choice([10, 100])}, 0.0,
|
||||
lambda x: x),
|
||||
set([80, 120]))
|
||||
{80, 120})
|
||||
assertProduces(
|
||||
lambda: explore(
|
||||
{"v": 100.0}, {"v": lambda: random.choice([10, 100])}, 0.0,
|
||||
lambda x: x),
|
||||
set([80.0, 120.0]))
|
||||
{80.0, 120.0})
|
||||
assertProduces(
|
||||
lambda: explore(
|
||||
{"v": 100.0}, {"v": lambda: random.choice([10, 100])}, 1.0,
|
||||
lambda x: x),
|
||||
set([10.0, 100.0]))
|
||||
{10.0, 100.0})
|
||||
|
||||
def testYieldsTimeToOtherTrials(self):
|
||||
pbt, runner = self.basicSetup()
|
||||
|
||||
@@ -172,7 +172,7 @@ class TrialRunner(object):
|
||||
if max_debug == start_num:
|
||||
break
|
||||
|
||||
for local_dir in sorted(set([t.local_dir for t in self._trials])):
|
||||
for local_dir in sorted({t.local_dir for t in self._trials}):
|
||||
messages.append("Result logdir: {}".format(local_dir))
|
||||
for state, trials in sorted(states.items()):
|
||||
limit = limit_per_state[state]
|
||||
|
||||
@@ -464,9 +464,11 @@ class Worker(object):
|
||||
final_results = self.retrieve_and_deserialize(plain_object_ids, 0)
|
||||
# Construct a dictionary mapping object IDs that we haven't gotten yet
|
||||
# to their original index in the object_ids argument.
|
||||
unready_ids = dict((plain_object_ids[i].binary(), i)
|
||||
for (i, val) in enumerate(final_results)
|
||||
if val is plasma.ObjectNotAvailable)
|
||||
unready_ids = {
|
||||
plain_object_ids[i].binary(): i
|
||||
for (i, val) in enumerate(final_results)
|
||||
if val is plasma.ObjectNotAvailable
|
||||
}
|
||||
was_blocked = (len(unready_ids) > 0)
|
||||
# Try reconstructing any objects we haven't gotten yet. Try to get them
|
||||
# until at least get_timeout_milliseconds milliseconds passes, then
|
||||
|
||||
Reference in New Issue
Block a user