text
stringlengths
1
93.6k
print("Failure: File cannot be read.")
def test_csv_output(self):
""" Verify that csv output file contains the expected elements"""
try:
mock_country = "MacedoniaMock"
mock_data = [
"1 : Skopje Panorama, Skopje",
"2 : Chic & Cozy Central Loft, Skopje",
"3 : Villa Dislievski, Ohrid",
"4 : Velestovo House, Ohrid",
"5 : Ibis Skopje City Center, Skopje",
"6 : Villa Tabana, Ohrid",
"7 : Villa Mishe, Ohrid",
"8 : Navona 58, Skopje",
"9 : Hotel Monako & Fish Restaurant Skopje, Skopje",
"10 : Villa Toneli, Skopje",
]
b.save_data(mock_data, out_format="csv", country=mock_country)
assert os.path.isfile("hotels-in-{}.csv".format(mock_country))
with open("hotels-in-{}.csv".format(mock_country)) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=",")
line_count = 0
for row in csv_reader:
name = mock_data[line_count].split(", ")[0].split(": ")[1]
city = mock_data[line_count].split(", ")[1]
# Assert that the first element in the output row is the item number
self.assertEqual(str(line_count + 1), row[0].strip())
# Assert that the second element in the output row is the hotel name
self.assertEqual(name, row[1].strip())
# Assert that the third element in the output row is the city
self.assertEqual(city, row[2].strip())
line_count += 1
# Assert that the number of output items is equal to the number of input items.
self.assertEqual(len(mock_data), line_count)
except IOError:
print("Failure: File cannot be read.")
if __name__ == "__main__":
unittest.main()
# <FILESEP>
import argparse
import os
import pickle
from multiprocessing import Process, Manager
import numpy as np
from torchdistill.common.file_util import get_file_path_list
from eq.conversion import sympy2sequence, sympy2zss_module
from eq.eval import compute_distances
def get_argparser():
parser = argparse.ArgumentParser(description='Dataset comparator')
parser.add_argument('--src_eq', required=True, help='source equation dir path')
parser.add_argument('--src_tabular', required=True, help='source tabular data dir path')
parser.add_argument('--src_delim', default=' ', help='delimiter in src data')
parser.add_argument('--dst_eq', required=True, help='destination equation dir path')
parser.add_argument('--dst_tabular', required=True, help='destination tabular data dir path')
parser.add_argument('--dst_delim', default=' ', help='destination in src data')
parser.add_argument('--mode', default='intersection', help='comparison mode')
return parser
def load_sympy_equation(file_path):
with open(file_path, 'rb') as fp:
eq_sympy = pickle.load(fp)
return eq_sympy.evalf()
def compute_stats(eqs, message):
print(f'\n{message}')
seq_length_list = list()
for eq in eqs:
eq_tree_sequence = sympy2sequence(eq, returns_binary_tree=True)
seq_length_list.append(len(eq_tree_sequence))
seq_lengths = np.array(seq_length_list)
print(f'{len(eqs)} equations')
print('Sequence length')
print(f'Min: {seq_lengths.min()}')
print(f'Max: {seq_lengths.max()}')
print(f'Mean: {seq_lengths.mean()}')
print(f'Median: {np.median(seq_lengths)}')
def load_tabular_dataset(file_path, delimiter):
mat = np.loadtxt(file_path, delimiter=delimiter)
return mat