Skip to content

Commit 1181e36

Browse files
committed
Merge branch 'main' of https://github.com/bigcode-project/open-eval into main
2 parents 88ff3df + 5e962c5 commit 1181e36

File tree

1,324 files changed

+85315
-54758
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,324 files changed

+85315
-54758
lines changed

RECORD.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- Wen-Ding Li
3232
- Ming Xu
3333
- Zhihan Zhang
34+
- Indraneil Paul
3435

3536
## Round 2: Manual Code Refinement
3637
- Terry Yue Zhuo
@@ -45,6 +46,7 @@
4546
- Dmitry Abulkhanov
4647
- Wen-Ding Li
4748
- Wenhao Yu
49+
- Indraneil Paul
4850

4951
## Round 3: Data Quality Check
5052
- Terry Yue Zhuo

data/clean/f_227_indraneil.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import random
2+
import seaborn as sns
3+
import numpy as np
4+
from matplotlib import pyplot as plt
5+
6+
def f_227(length, range_limit=100, seed=0):
7+
"""
8+
Create a list of random numbers, sort them and record the distribution of the numbers in a histogram using
9+
default settings in a deterministic seaborn plot. Return the axes object and the list of random numbers.
10+
11+
Parameters:
12+
length (int): The length of the list of random numbers.
13+
range_limit (int, Optional): The range of the random numbers. Defaults to 100. Must be greater than 1.
14+
seed (int, Optional): The seed value for the random number generator. Defaults to 0.
15+
16+
Returns:
17+
Tuple[matplotlib.axes._subplots.AxesSubplot, List[int]]: The axes object with the plot and the list of random numbers.
18+
19+
Requirements:
20+
- random
21+
- matplotlib.pyplot
22+
- seaborn
23+
- numpy
24+
25+
Raises:
26+
ValueError: If range_limit is less than or equal to 1.
27+
28+
Example:
29+
>>> import matplotlib.pyplot as plt
30+
>>> ax, data = f_227(1000, 100, 24) # Generate a list of 1000 random numbers between 1 and 100
31+
>>> isinstance(ax, plt.Axes)
32+
True
33+
"""
34+
if range_limit <= 1:
35+
raise ValueError("range_limit must be greater than 1")
36+
37+
random.seed(seed)
38+
np.random.seed(seed)
39+
40+
random_numbers = [random.randint(1, range_limit) for _ in range(length)]
41+
random_numbers.sort()
42+
43+
# Initialize a fresh plot
44+
plt.figure()
45+
plot = sns.histplot(random_numbers, kde=False)
46+
47+
return plot.axes, random_numbers
48+
49+
50+
import unittest
51+
import doctest
52+
53+
54+
class TestCases(unittest.TestCase):
55+
56+
def test_case_1(self):
57+
_, data = f_227(1000)
58+
self.assertEqual(len(data), 1000)
59+
60+
def test_case_2(self):
61+
with self.assertRaises(ValueError):
62+
_, data = f_227(1000, -3, 42)
63+
64+
65+
def test_case_3(self):
66+
_, data = f_227(20, 75, 77)
67+
self.assertEqual(data, [1, 4, 15, 19, 23, 25, 25, 26, 31, 31, 33, 36, 38, 42, 61, 64, 65, 65, 72, 72])
68+
self.assertTrue(all(1 <= num <= 75 for num in data))
69+
70+
def test_case_4(self):
71+
ax, data = f_227(1000, 75)
72+
target = np.array([98, 103, 106, 73, 87, 92, 94, 84, 90, 95, 78])
73+
self.assertTrue((ax.containers[0].datavalues == target).all())
74+
75+
def test_case_5(self):
76+
_, data1 = f_227(1000, seed=42)
77+
_, data2 = f_227(1000, seed=42)
78+
self.assertEqual(data1, data2)
79+
80+
81+
def run_tests():
82+
suite = unittest.TestSuite()
83+
suite.addTest(unittest.makeSuite(TestCases))
84+
runner = unittest.TextTestRunner()
85+
runner.run(suite)
86+
87+
88+
if __name__ == "__main__":
89+
doctest.testmod()
90+
run_tests()

data/clean/f_228_indraneil.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import heapq
2+
import math
3+
import matplotlib.pyplot as plt
4+
5+
6+
def f_228(l1, l2, N=10):
7+
"""
8+
Find the N biggest differences between the respective elements of the list 'l1' and list 'l2',
9+
square the differences, take the square root and return the plotted values as a matplotlib Axes object.
10+
11+
Parameters:
12+
l1 (list): A list of numbers.
13+
l2 (list): A list of numbers.
14+
N (int): Number of largest differences to consider. Default is 10.
15+
16+
Returns:
17+
matplotlib.axes._subplots.AxesSubplot: A matplotlib Axes object with the plotted differences.
18+
19+
Requirements:
20+
- heapq
21+
- math
22+
- matplotlib.pyplot
23+
24+
Example:
25+
>>> l1 = [99, 86, 90, 70, 86, 95, 56, 98, 80, 81]
26+
>>> l2 = [21, 11, 21, 1, 26, 40, 4, 50, 34, 37]
27+
>>> ax = f_228(l1, l2)
28+
>>> type(ax)
29+
<class 'matplotlib.axes._axes.Axes'>
30+
"""
31+
largest_diff_indices = heapq.nlargest(N, range(len(l1)), key=lambda i: abs(l1[i] - l2[i]))
32+
largest_diffs = [math.sqrt((l1[i] - l2[i])**2) for i in largest_diff_indices]
33+
34+
fig, ax = plt.subplots()
35+
ax.plot(largest_diffs)
36+
37+
return ax
38+
39+
40+
import unittest
41+
import doctest
42+
43+
44+
class TestCases(unittest.TestCase):
45+
def test_case_1(self):
46+
l1 = [99, 86, 90, 70, 86, 95, 56, 98, 80, 81]
47+
l2 = [21, 11, 21, 1, 26, 40, 4, 50, 34, 37]
48+
ax = f_228(l1, l2)
49+
self.assertIsInstance(ax, plt.Axes)
50+
self.assertEqual(len(ax.lines[0].get_ydata()), 10)
51+
52+
def test_case_2(self):
53+
l1 = [10, 20, 30, 40, 50]
54+
l2 = [1, 2, 3, 4, 5]
55+
ax = f_228(l1, l2, 3)
56+
self.assertIsInstance(ax, plt.Axes)
57+
self.assertEqual(len(ax.lines[0].get_ydata()), 3)
58+
59+
def test_case_3(self):
60+
l1 = [0, 10, 20, 30, 40, 50]
61+
l2 = [0, 0, 0, 0, 0, 0]
62+
ax = f_228(l1, l2)
63+
self.assertIsInstance(ax, plt.Axes)
64+
self.assertEqual(len(ax.lines[0].get_ydata()), 6)
65+
66+
def test_case_4(self):
67+
l1 = [1, 2, 3, 4, 5]
68+
l2 = [5, 4, 3, 2, 1]
69+
ax = f_228(l1, l2)
70+
self.assertIsInstance(ax, plt.Axes)
71+
self.assertEqual(len(ax.lines[0].get_ydata()), 5)
72+
73+
def test_case_5(self):
74+
l1 = [0, 0, 0, 0, 0]
75+
l2 = [0, 0, 0, 0, 0]
76+
ax = f_228(l1, l2)
77+
self.assertIsInstance(ax, plt.Axes)
78+
self.assertEqual(len(ax.lines[0].get_ydata()), 5)
79+
80+
81+
def run_tests():
82+
suite = unittest.TestSuite()
83+
suite.addTest(unittest.makeSuite(TestCases))
84+
runner = unittest.TextTestRunner()
85+
runner.run(suite)
86+
87+
88+
if __name__ == "__main__":
89+
doctest.testmod()
90+
run_tests()

data/clean/f_229_indraneil.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import re
2+
import json
3+
from collections import Counter
4+
5+
6+
def f_229(json_str, top_n=10):
7+
"""
8+
Extract all URLs from a string-serialized JSON dict using a specific URL pattern and return a dict
9+
with the URLs as keys and the number of times they appear as values.
10+
11+
Parameters:
12+
json_str (str): The JSON string.
13+
top_n (int, Optional): The number of URLs to return. Defaults to 10.
14+
15+
Returns:
16+
dict: A dict with URLs as keys and the number of times they appear as values.
17+
18+
Requirements:
19+
- re
20+
- json
21+
- collections.Counter
22+
23+
Example:
24+
>>> f_229('{"name": "John", "website": "https://www.example.com"}')
25+
{'https://www.example.com': 1}
26+
"""
27+
pattern = r'(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})'
28+
data = json.loads(json_str)
29+
urls = []
30+
31+
def extract(dictionary):
32+
for key, value in dictionary.items():
33+
if isinstance(value, dict):
34+
extract(value)
35+
elif isinstance(value, str) and re.match(pattern, value):
36+
urls.append(value)
37+
38+
extract(data)
39+
if not urls:
40+
return {}
41+
elif len(urls) <= top_n:
42+
return dict(Counter(urls))
43+
44+
return dict(Counter(urls).most_common(top_n))
45+
46+
47+
import unittest
48+
import doctest
49+
50+
51+
class TestCases(unittest.TestCase):
52+
53+
def test_case_1(self):
54+
json_str = '{"name": "John", "website": "qwerthttps://www.example.com"}'
55+
result = f_229(json_str)
56+
self.assertEqual(result, {})
57+
58+
def test_case_2(self):
59+
json_str = '{"name": "John", "social": {"twitter": "https://twitter.com/john", "linkedin": "https://linkedin.com/in/john"}, "website": "https://linkedin.com/in/john"}'
60+
result = f_229(json_str)
61+
self.assertEqual(result, {'https://twitter.com/john': 1, 'https://linkedin.com/in/john': 2})
62+
result = f_229(json_str, 1)
63+
self.assertEqual(result, {'https://linkedin.com/in/john': 2})
64+
65+
def test_case_3(self):
66+
json_str = 'This is an adversarial input 0061'
67+
with self.assertRaises(json.decoder.JSONDecodeError):
68+
result = f_229(json_str)
69+
70+
def test_case_4(self):
71+
json_str = '{"name": "John", "age": 30}'
72+
result = f_229(json_str)
73+
self.assertEqual(result, {})
74+
75+
def test_case_5(self):
76+
json_str = '{"name": "John", "website": "example.com", "blog": "www.johnblog.com"}'
77+
result = f_229(json_str)
78+
self.assertEqual(result, {'www.johnblog.com': 1})
79+
80+
81+
def run_tests():
82+
suite = unittest.TestSuite()
83+
suite.addTest(unittest.makeSuite(TestCases))
84+
runner = unittest.TextTestRunner()
85+
runner.run(suite)
86+
87+
88+
if __name__ == "__main__":
89+
doctest.testmod()
90+
run_tests()

data/clean/f_230_indraneil.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import numpy as np
2+
from collections import Counter
3+
import matplotlib.pyplot as plt
4+
5+
def f_230(L):
6+
"""
7+
Analyze an "L" list by calculating the mean, median, mode, and standard deviation.
8+
Visualize the data by returning a histogram plot.
9+
10+
Parameters:
11+
L (list): Input list.
12+
13+
Returns:
14+
dict: A dictionary with the mean, median, mode, and standard deviation of 'L'.
15+
16+
Requirements:
17+
- numpy
18+
- collections.Counter
19+
- matplotlib.pyplot
20+
21+
Example:
22+
>>> L = [1, 2, 3, 4, 5, 6, 7, 8, 9]
23+
>>> stats = f_230(L)
24+
>>> print(stats["mean"])
25+
5.0
26+
>>> print(stats["median"])
27+
5.0
28+
>>> print(stats["mode"])
29+
1
30+
"""
31+
mean = np.mean(L)
32+
median = np.median(L)
33+
mode = Counter(L).most_common(1)[0][0]
34+
std_dev = np.std(L)
35+
36+
plt.hist(L, bins='auto')
37+
plt.title('Histogram of Data')
38+
plt.xlabel('Value')
39+
plt.ylabel('Frequency')
40+
41+
return {'mean': mean, 'median': median, 'mode': mode, 'std_dev': std_dev, 'plot': plt.gca()}
42+
43+
44+
import unittest
45+
import doctest
46+
47+
48+
class TestCases(unittest.TestCase):
49+
50+
def test_case_1(self):
51+
L = [1, 2, 3, 4, 5, 6, 7, 8, 9]
52+
stats = f_230(L)
53+
self.assertAlmostEqual(stats['mean'], np.mean(L))
54+
self.assertAlmostEqual(stats['median'], np.median(L))
55+
self.assertEqual(stats['mode'], 1)
56+
self.assertAlmostEqual(stats['std_dev'], np.std(L))
57+
self.assertIsInstance(stats['plot'], plt.Axes)
58+
59+
def test_case_2(self):
60+
L = [5, 5, 5, 5, 5]
61+
stats = f_230(L)
62+
self.assertAlmostEqual(stats['mean'], 5.0)
63+
self.assertAlmostEqual(stats['median'], 5.0)
64+
self.assertEqual(stats['mode'], 5)
65+
self.assertAlmostEqual(stats['std_dev'], 0.0)
66+
self.assertIsInstance(stats['plot'], plt.Axes)
67+
68+
def test_case_3(self):
69+
L = [1, 2, 3, 4, 5, 5, 6, 7, 8, 8, 8, 9]
70+
stats = f_230(L)
71+
self.assertAlmostEqual(stats['mean'], np.mean(L))
72+
self.assertAlmostEqual(stats['median'], np.median(L))
73+
self.assertEqual(stats['mode'], 8)
74+
self.assertAlmostEqual(stats['std_dev'], np.std(L))
75+
self.assertIsInstance(stats['plot'], plt.Axes)
76+
77+
def test_case_4(self):
78+
L = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
79+
stats = f_230(L)
80+
self.assertAlmostEqual(stats['mean'], np.mean(L))
81+
self.assertAlmostEqual(stats['median'], np.median(L))
82+
self.assertEqual(stats['mode'], 10)
83+
self.assertAlmostEqual(stats['std_dev'], np.std(L))
84+
self.assertIsInstance(stats['plot'], plt.Axes)
85+
86+
def test_case_5(self):
87+
L = [5]
88+
stats = f_230(L)
89+
self.assertAlmostEqual(stats['mean'], 5.0)
90+
self.assertAlmostEqual(stats['median'], 5.0)
91+
self.assertEqual(stats['mode'], 5)
92+
self.assertAlmostEqual(stats['std_dev'], 0.0)
93+
self.assertIsInstance(stats['plot'], plt.Axes)
94+
95+
96+
def run_tests():
97+
suite = unittest.TestSuite()
98+
suite.addTest(unittest.makeSuite(TestCases))
99+
runner = unittest.TextTestRunner()
100+
runner.run(suite)
101+
102+
103+
if __name__ == "__main__":
104+
doctest.testmod()
105+
run_tests()

0 commit comments

Comments
 (0)