Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

restore python 2.5 compat

  • Loading branch information...
commit c953f1c99b3df293d8810eaaacc272e04773ea40 1 parent 5f86e57
@ogrisel ogrisel authored
View
6 scikits/learn/datasets/lfw.py
@@ -267,9 +267,9 @@ def _load_lfw_pairs(index_file_path, data_folder_path, slice_=None,
"""
# parse the index file to find the number of pairs to be able to allocate
# the right amount of memory before starting to decode the jpeg files
- with open(index_file_path) as f:
- splitted_lines = [l.strip().split('\t') for l in f.readlines()]
- pair_specs = [l for l in splitted_lines if len(l) > 2]
+ splitted_lines = [l.strip().split('\t')
+ for l in open(index_file_path, 'rb').readlines()]
+ pair_specs = [sl for sl in splitted_lines if len(sl) > 2]
n_pairs = len(pair_specs)
# interating over the metadata lines for each pair to find the filename to
View
50 scikits/learn/datasets/tests/test_lfw.py
@@ -61,31 +61,35 @@ def setup_module():
imsave(file_path, uniface)
# add some random file pollution to test robustness
- with open(os.path.join(LFW_HOME, 'lfw_funneled', '.test.swp'), 'wb') as f:
- f.write('Text file to be ignored by the dataset loader.')
+ f = open(os.path.join(LFW_HOME, 'lfw_funneled', '.test.swp'), 'wb')
+ f.write('Text file to be ignored by the dataset loader.')
+ f.close()
# generate some pairing metadata files using the same format as LFW
- with open(os.path.join(LFW_HOME, 'pairsDevTrain.txt'), 'wb') as f:
- f.write("10\n")
- more_than_two = [name for name, count in counts.iteritems()
- if count >= 2]
- for i in range(5):
- name = rng.choice(more_than_two)
- first, second = rng.sample(range(counts[name]), 2)
- f.write('%s\t%d\t%d\n' % (name, first, second))
-
- for i in range(5):
- first_name, second_name = rng.sample(FAKE_NAMES, 2)
- first_index = rng.choice(range(counts[first_name]))
- second_index = rng.choice(range(counts[second_name]))
- f.write('%s\t%d\t%s\t%d\n' % (first_name, first_index,
- second_name, second_index))
-
- with open(os.path.join(LFW_HOME, 'pairsDevTest.txt'), 'wb') as f:
- f.write("Fake place holder that won't be tested")
-
- with open(os.path.join(LFW_HOME, 'pairs.txt'), 'wb') as f:
- f.write("Fake place holder that won't be tested")
+ f = open(os.path.join(LFW_HOME, 'pairsDevTrain.txt'), 'wb')
+ f.write("10\n")
+ more_than_two = [name for name, count in counts.iteritems()
+ if count >= 2]
+ for i in range(5):
+ name = rng.choice(more_than_two)
+ first, second = rng.sample(range(counts[name]), 2)
+ f.write('%s\t%d\t%d\n' % (name, first, second))
+
+ for i in range(5):
+ first_name, second_name = rng.sample(FAKE_NAMES, 2)
+ first_index = rng.choice(range(counts[first_name]))
+ second_index = rng.choice(range(counts[second_name]))
+ f.write('%s\t%d\t%s\t%d\n' % (first_name, first_index,
+ second_name, second_index))
+ f.close()
+
+ f = open(os.path.join(LFW_HOME, 'pairsDevTest.txt'), 'wb')
+ f.write("Fake place holder that won't be tested")
+ f.close()
+
+ f = open(os.path.join(LFW_HOME, 'pairs.txt'), 'wb')
+ f.write("Fake place holder that won't be tested")
+ f.close()
def teardown_module():
Please sign in to comment.
Something went wrong with that request. Please try again.