Skip to content

Commit 2dae724

Browse files
committed
Patch randomness in eval
1 parent fc9e245 commit 2dae724

13 files changed

+100
-48
lines changed

data/raw/f_243_indraneil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class TestCases(unittest.TestCase):
5757

5858
def setUp(self):
5959
# Set up the test file path
60-
self.temp_dir = tempfile.gettempdir()
60+
self.temp_dir = tempfile.mkdtemp()
6161
self.test_file_path = f"{self.temp_dir}/test_log.json"
6262

6363
def tearDown(self):

data/raw/f_245_indraneil.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def f_1238(obj_list, attr, num_bins=30, seed=0):
6161
class TestCases(unittest.TestCase):
6262
def test_case_1(self):
6363
# Input 1: Simple list of objects with integer values from 0 to 9
64+
random.seed(1)
6465
obj_list = [Object(value=i) for i in range(10)]
6566
ax = f_1238(obj_list, 'value')
6667

@@ -73,6 +74,7 @@ def test_case_1(self):
7374

7475
def test_case_2(self):
7576
# Input 2: List of objects with random Gaussian values
77+
random.seed(2)
7678
obj_list = [Object() for _ in range(100)]
7779
ax = f_1238(obj_list, 'value', seed=77)
7880

@@ -87,6 +89,7 @@ def test_case_2(self):
8789

8890
def test_case_3(self):
8991
# Input 3: List of objects with fixed value
92+
random.seed(3)
9093
obj_list = [Object(value=5) for _ in range(50)]
9194
ax = f_1238(obj_list, 'value', seed=4)
9295

@@ -116,6 +119,7 @@ def test_case_4(self):
116119

117120
def test_case_5(self):
118121
# Input 5: Large list of objects
122+
random.seed(5)
119123
obj_list = [Object(value=random.gauss(0, 5)) for _ in range(1000)]
120124
ax = f_1238(obj_list, 'value')
121125

data/raw/f_247_indraneil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def f_247(data, save_plot=False, plot_path=None):
2828
2929
Example:
3030
>>> import tempfile
31-
>>> temp_dir = tempfile.gettempdir()
31+
>>> temp_dir = tempfile.mkdtemp()
3232
>>> f_247([('A', 1, 1, 1), ('B', 2, 2, 2)], save_plot=True, plot_path=f"{temp_dir}/temp_plot.png")[0]
3333
array([[ 8.66025404e-01, 4.09680598e-17],
3434
[-8.66025404e-01, 4.09680598e-17]])

data/raw/f_2695_junda_james.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ class TestCases(unittest.TestCase):
6666
def setUp(self):
6767
# Create a dummy image for testing
6868
np.random.seed(42)
69-
self.dummy_img_path = os.path.join(tempfile.gettempdir(), 'test_image.jpg')
69+
self.dummy_img_path = os.path.join(tempfile.mkdtemp(), 'test_image.jpg')
7070
dummy_img = np.random.randint(0, 255, (20, 20, 3), dtype=np.uint8)
7171
cv2.imwrite(self.dummy_img_path, dummy_img)
7272

7373
def tearDown(self):
7474
# Cleanup the dummy image
75-
os.remove(self.dummy_img_path)
75+
if os.path.exists(self.dummy_img_path):
76+
os.remove(self.dummy_img_path)
7677

7778
def test_valid_input(self):
7879
def dummy_onpick(event):

data/raw/f_2724_hanhu.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
def f_2726(X, y, n_splits, batch_size, epochs):
66
"""
77
Trains a simple neural network on provided data using k-fold cross-validation.
8-
The network has one hidden layer with 50 neurons and ReLU activation, and
8+
The network has one hidden layer with 20 neurons and ReLU activation, and
99
an output layer with sigmoid activation for binary classification.
1010
1111
Parameters:
1212
X (numpy.array): The input data.
1313
y (numpy.array): The target data.
1414
n_splits (int): The number of splits for k-fold cross-validation. Default is 5.
1515
batch_size (int): The size of the batch used during training. Default is 32.
16-
epochs (int): The number of epochs for training the model. Default is 10.
16+
epochs (int): The number of epochs for training the model. Default is 1.
1717
1818
Returns:
1919
list: A list containing the training history of the model for each fold. Each history
@@ -47,7 +47,7 @@ def f_2726(X, y, n_splits, batch_size, epochs):
4747
y_train, y_test = y[train_index], y[test_index]
4848

4949
model = tf.keras.models.Sequential([
50-
tf.keras.layers.Dense(50, activation='relu'),
50+
tf.keras.layers.Dense(20, activation='relu'),
5151
tf.keras.layers.Dense(1, activation='sigmoid')
5252
])
5353

@@ -70,7 +70,7 @@ def setUp(self):
7070
self.y = np.random.randint(0, 2, 100)
7171
self.n_splits = 5
7272
self.batch_size = 32
73-
self.epochs = 10
73+
self.epochs = 1
7474

7575
def test_return_type(self):
7676
"""Test that the function returns a list."""
@@ -101,9 +101,9 @@ def test_effect_of_different_batch_sizes(self):
101101

102102
def test_effect_of_different_epochs(self):
103103
"""Test function behavior with different epochs."""
104-
for epochs in [5, 20]:
105-
result = f_2726(self.X, self.y, self.n_splits, self.batch_size, epochs)
106-
self.assertEqual(len(result), self.n_splits) # Validating function execution
104+
epochs=5
105+
result = f_2726(self.X, self.y, self.n_splits, self.batch_size, epochs)
106+
self.assertEqual(len(result), self.n_splits) # Validating function execution
107107

108108

109109
def run_tests():

data/raw/f_289_indraneil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def f_289(file_path, regex_pattern=r'\(.+?\)|\w+|[\W_]+'):
2323
2424
Example:
2525
>>> import tempfile
26-
>>> temp_dir = tempfile.gettempdir()
26+
>>> temp_dir = tempfile.mkdtemp()
2727
>>> file_path = os.path.join(temp_dir, 'data.csv')
2828
>>> with open(file_path, 'w', newline='') as file:
2929
... writer = csv.writer(file)
@@ -52,7 +52,7 @@ def f_289(file_path, regex_pattern=r'\(.+?\)|\w+|[\W_]+'):
5252

5353

5454
class TestCases(unittest.TestCase):
55-
base_tmp_dir = tempfile.gettempdir()
55+
base_tmp_dir = tempfile.mkdtemp()
5656
test_data_dir = f"{base_tmp_dir}/test"
5757

5858
def setUp(self):

data/raw/f_290_indraneil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def f_290(file_path: str, regex_pattern=r'\(.+?\)|\w') -> dict:
2222
2323
Example:
2424
>>> import tempfile
25-
>>> temp_dir = tempfile.gettempdir()
25+
>>> temp_dir = tempfile.mkdtemp()
2626
>>> file_path = os.path.join(temp_dir, 'sample_data.json')
2727
>>> with open(file_path, 'w') as file:
2828
... json.dump({'content': 'This is a (sample) text with some (matches) and characters.'}, file)

data/raw/f_294_indraneil.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class TestCases(unittest.TestCase):
5454

5555
def setUp(self):
5656
self.extensions = ['*.txt', '*.md', '*.csv']
57-
self.base_tmp_dir = tempfile.gettempdir()
57+
self.base_tmp_dir = tempfile.mkdtemp()
5858
self.test_directory = f"{self.base_tmp_dir}/test/"
5959
os.makedirs(self.test_directory, exist_ok=True)
6060

@@ -70,9 +70,9 @@ def setUp(self):
7070
# Write the sample data to files
7171
for filename, content in sample_files_data.items():
7272
with (
73-
open(os.path.join(self.test_directory, filename), 'w')
74-
if os.path.exists(os.path.join(self.test_directory, filename))
75-
else open(os.path.join(self.test_directory, filename), 'x')
73+
open(os.path.join(self.test_directory, filename), 'w')
74+
if os.path.exists(os.path.join(self.test_directory, filename))
75+
else open(os.path.join(self.test_directory, filename), 'x')
7676
) as file:
7777
file.write(content)
7878
return super().setUp()

data/raw/f_321_indraneil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def f_321(file_path):
4848
class TestCases(unittest.TestCase):
4949
def setUp(self):
5050
# Preparing sample JSON data for testing
51-
self.base_tmp_dir = tempfile.gettempdir()
51+
self.base_tmp_dir = tempfile.mkdtemp()
5252
self.test_data_folder = f"{self.base_tmp_dir}/test"
5353
os.makedirs(self.test_data_folder, exist_ok=True)
5454

data/raw/f_367_jenny.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def f_367(file_path="data.csv", columns=["A", "B", "C"]):
66
"""
77
Read a CSV file into a Pandas DataFrame, convert numeric values into floats,and draw a line chart of data in the specified columns.
88
In addition, compute the cube-root of the data.
9-
9+
1010
Parameters:
1111
- file_path (str): Path to the CSV file. Default is 'data.csv'.
1212
- columns (list of str): List of column names from the data to plot.
@@ -17,7 +17,7 @@ def f_367(file_path="data.csv", columns=["A", "B", "C"]):
1717
- DataFrame: A pandas DataFrame of the data in the CSV file.
1818
- Axes: A matplotlib Axes object showing the plotted data.
1919
- Series: A pandas Series containing the cube-root of the data.
20-
20+
2121
Requirements:
2222
- pandas
2323
- numpy
@@ -31,7 +31,7 @@ def f_367(file_path="data.csv", columns=["A", "B", "C"]):
3131
>>> ax
3232
<matplotlib.axes._subplots.AxesSubplot object at 0x7f24b00f4a90>
3333
>>> croot
34-
0 1.0
34+
0 1.0
3535
"""
3636
df = pd.read_csv(file_path, dtype=float)
3737
ax = df[columns].plot()
@@ -46,6 +46,11 @@ def f_367(file_path="data.csv", columns=["A", "B", "C"]):
4646
import os
4747

4848

49+
def round_dict(d, digits):
50+
return {k: {i: round(v, digits) for i, v in subdict.items()} for k, subdict in
51+
d.items()}
52+
53+
4954
class TestCases(unittest.TestCase):
5055
def setUp(self):
5156
self.test_dir = tempfile.TemporaryDirectory()
@@ -87,8 +92,13 @@ def test_case_1(self):
8792
self.assertTrue((df["A"].tolist() == [1, 2, 3]))
8893
self.assertTrue((df["B"].tolist() == [4, 5, 6]))
8994
self.assertTrue((df["C"].tolist() == [7, 8, 9]))
90-
self.assertEqual(croot.to_dict(), {'A': {0: 1.0, 1: 1.2599210498948734, 2: 1.4422495703074083}, 'B': {0: 1.5874010519681996, 1: 1.7099759466766968, 2: 1.8171205928321394}, 'C': {0: 1.9129311827723894, 1: 2.0, 2: 2.080083823051904}})
91-
95+
rounded_croot = round_dict(croot.to_dict(), 6)
96+
self.assertEqual(rounded_croot,
97+
{'A': {0: 1.0, 1: 1.259921, 2: 1.44225},
98+
'B': {0: 1.587401, 1: 1.709976,
99+
2: 1.817121},
100+
'C': {0: 1.912931, 1: 2.0, 2: 2.080084}})
101+
92102
def test_case_2(self):
93103
file_path = self.temp_files["int"]
94104
with self.assertRaises(KeyError):
@@ -104,8 +114,14 @@ def test_case_3(self):
104114
self.assertTrue(df["IntColumn"].equals(pd.Series([1.0, 2.0, 3.0])))
105115
self.assertTrue(df["FloatColumn"].equals(pd.Series([1.1, 2.2, 3.3])))
106116
self.assertTrue(df["StringColumn"].equals(pd.Series([4.0, 5.0, 6.0])))
107-
self.assertEqual(croot.to_dict(), {'IntColumn': {0: 1.0, 1: 1.2599210498948734, 2: 1.4422495703074083}, 'FloatColumn': {0: 1.0322801154563672, 1: 1.300591446851387, 2: 1.4888055529538275}, 'StringColumn': {0: 1.5874010519681996, 1: 1.7099759466766968, 2: 1.8171205928321394}})
108-
117+
rounded_croot = round_dict(croot.to_dict(), 6)
118+
self.assertEqual(rounded_croot, {
119+
'IntColumn': {0: 1.0, 1: 1.259921, 2: 1.44225},
120+
'FloatColumn': {0: 1.03228, 1: 1.300591,
121+
2: 1.488806},
122+
'StringColumn': {0: 1.587401, 1: 1.709976,
123+
2: 1.817121}})
124+
109125
def test_case_4(self):
110126
file_path = self.temp_files["varied_invalid"]
111127
with self.assertRaises(Exception):

0 commit comments

Comments
 (0)