import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array(
                [
                    [0, 1, 2, 3, 5, 6, 7, 8],
                    [4, 5, 6, 7, 5, 3, 2, 5],
                    [8, 9, 10, 11, 4, 5, 3, 5],
                ]
            )
            low = 1
            high = 5
        elif test_case_id == 2:
            np.random.seed(42)
            a = np.random.rand(20, 10)
            low = np.random.randint(1, 8)
            high = np.random.randint(low + 1, 10)
        return a, low, high

    def generate_ans(data):
        _a = data
        a, low, high = _a
        result = a[:, low:high]
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
a, low, high = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame({
                'A': [0, 4, 8],
                'B': [1, 5, 9],
                'C': [2, 6, 10],
                'D': [3, 7, 11],
                'E': [5, 5, 4],
                'F': [6, 3, 5],
                'G': [7, 2, 3],
                'H': [8, 5, 5]
            })
            start_col = 'B'
            end_col = 'E'
        elif test_case_id == 2:
            np.random.seed(42)
            data = np.random.rand(20, 8)
            columns = list('ABCDEFGH')
            df = pd.DataFrame(data, columns=columns)
            start_col = np.random.choice(columns[:-3])
            end_col = columns[columns.index(start_col) + np.random.randint(1, 4)]
        return df, start_col, end_col

    def generate_ans(data):
        _df = data
        df, start_col, end_col = _df
        result = df.loc[:, start_col:end_col]
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_frame_equal(result, ans)
    return 1

exec_context = r"""
import pandas as pd
import numpy as np
df, start_col, end_col = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array(
                [
                    [0, 1, 2, 3, 5, 6, 7, 8],
                    [4, 5, 6, 7, 5, 3, 2, 5],
                    [8, 9, 10, 11, 4, 5, 3, 5],
                ]
            )
            low = 0
            high = 2
        elif test_case_id == 2:
            np.random.seed(42)
            a = np.random.rand(20, 10)
            low = np.random.randint(1, 8)
            high = np.random.randint(low + 1, 10)
        return a, low, high

    def generate_ans(data):
        _a = data
        a, low, high = _a
        result = a[low:high, :]
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
a, low, high = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame({
                'A': [0, 4, 8],
                'B': [1, 5, 9],
                'C': [2, 6, 10],
                'D': [3, 7, 11],
                'E': [5, 5, 4],
                'F': [6, 3, 5],
                'G': [7, 2, 3],
                'H': [8, 5, 5]
            })
            low = 0
            high = 2
        elif test_case_id == 2:
            np.random.seed(42)
            data = np.random.rand(20, 8)
            df = pd.DataFrame(data, columns=list('ABCDEFGH'))
            low = np.random.randint(1, 8)
            high = np.random.randint(low + 1, 10)
        return df, low, high

    def generate_ans(data):
        _df = data
        df, low, high = _df
        result = df.iloc[low:high]
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_frame_equal(result, ans)
    return 1

exec_context = r"""
import pandas as pd
import numpy as np
df, low, high = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array(
                [
                    [0, 1, 2, 3, 5, 6, 7, 8],
                    [4, 5, 6, 7, 5, 3, 2, 5],
                    [8, 9, 10, 11, 4, 5, 3, 5],
                ]
            )
            low = 1
            high = 10
        elif test_case_id == 2:
            np.random.seed(42)
            a = np.random.rand(20, 10)
            low = np.random.randint(1, 8)
            high = np.random.randint(low + 1, 10)
        return a, low, high

    def generate_ans(data):
        _a = data
        a, low, high = _a
        high = min(high, a.shape[1])
        result = a[:, low:high]
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
a, low, high = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame({
                'A': [0, 4, 8],
                'B': [1, 5, 9],
                'C': [2, 6, 10],
                'D': [3, 7, 11],
                'E': [5, 5, 4],
                'F': [6, 3, 5],
                'G': [7, 2, 3],
                'H': [8, 5, 5]
            })
            start_col = 'B'
            end_col = 'H'
        elif test_case_id == 2:
            df = pd.DataFrame(np.random.randint(0, 100, size=(10, 8)), columns=list('ABCDEFGH'))
            start_col = 'C'
            end_col = 'G'
        return df, start_col, end_col

    def generate_ans(data):
        df, start_col, end_col = data
        result = df.loc[:, start_col:end_col]
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_frame_equal(result, ans)
    return 1

exec_context = r"""
import pandas as pd
import numpy as np
df, start_col, end_col = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
string = "[[ 0.5544  0.4456], [ 0.8811  0.1189]]"

a = ... # put solution in this variable

a = np.array(np.matrix(string.replace(',', ';')))

import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            string = "[[ 0.5544  0.4456], [ 0.8811  0.1189]]"
        elif test_case_id == 2:
            np.random.seed(42)
            a = np.random.rand(5, 6)
            string = str(a).replace("\n", ",")
        return string

    def generate_ans(data):
        _a = data
        string = _a
        a = np.array(np.matrix(string.replace(",", ";")))
        return a

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
string = test_input
[insert]
result = a
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
string = "[[ 0.5544  0.4456], [ 0.8811  0.1189]]"

df = ... # put solution in this variable

df = pd.DataFrame(np.matrix(string.replace(',', ';')))

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            string = "[[ 0.5544  0.4456], [ 0.8811  0.1189]]"
        elif test_case_id == 2:
            np.random.seed(42)
            a = np.random.rand(5, 6)
            string = str(a).replace("\n", ",")
        return string

    def generate_ans(data):
        _a = data
        string = _a
        df = pd.DataFrame(np.matrix(string.replace(",", ";")))
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_frame_equal(result, ans)
    return 1

exec_context = r"""
import pandas as pd
import numpy as np
string = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import scipy.stats
result = scipy.stats.loguniform.rvs(a = min, b = max, size = n)

import pandas as pd
import numpy as np

min = 1
max = np.e
n = 10000

result = ... # put solution in this variable

import pandas as pd
import numpy as np
import copy
import tokenize, io
import scipy
from scipy.stats import ks_2samp

def generate_test_case(test_case_id):

    def define_test_input(test_case_id):
        if test_case_id == 1:
            low = 1
            high = np.e
            size = 10000
        return low, high, size

    def generate_ans(data):
        _a = data
        min, max, n = _a
        result = scipy.stats.loguniform.rvs(a=min, b=max, size=n)
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))

    return test_input, expected_result

def exec_test(result, ans):

    np.testing.assert_array_equal(result.shape, ans.shape)
    assert ks_2samp(result, ans)[0] <= 0.1

    return 1

exec_context = r"""
import numpy as np
min, max, n = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "while" not in tokens and "for" not in tokens


import numpy as np
import pandas as pd
A = pd.Series(np.random.randn(10,))
a = 2
b = 3

B = ... # put solution in this variable

B = np.empty(len(A))
for k in range(0, len(B)):
    if k == 0:
        B[k] = a*A[k]
    else:
        B[k] = a*A[k] + b*B[k-1]

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(42)
            A = pd.Series(
                np.random.randn(
                    10,
                )
            )
            a = 2
            b = 3
        elif test_case_id == 2:
            np.random.seed(42)
            A = pd.Series(
                np.random.randn(
                    30,
                )
            )
            a, b = np.random.randint(2, 10, (2,))
        return A, a, b

    def generate_ans(data):
        _a = data
        A, a, b = _a
        B = np.empty(len(A))
        for k in range(0, len(B)):
            if k == 0:
                B[k] = a * A[k]
            else:
                B[k] = a * A[k] + b * B[k - 1]
        return B

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
import pandas as pd
A, a, b = test_input
[insert]
result = B
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

B = pd.Series(np.empty(len(A)))
for k in range(0, len(B)):
    if k == 0:
        B[k] = a*A[k]
    else:
        B[k] = a*A[k] + b*B[k-1]

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(42)
            A = pd.Series(np.random.randn(10,))
            a = 2
            b = 3
        elif test_case_id == 2:
            np.random.seed(42)
            A = pd.Series(np.random.randn(30,))
            a, b = np.random.randint(2, 10, (2,))
        return A, a, b

    def generate_ans(data):
        _a = data
        A, a, b = _a
        B = pd.Series(np.empty(len(A)))
        for k in range(0, len(B)):
            if k == 0:
                B[k] = a * A[k]
            else:
                B[k] = a * A[k] + b * B[k - 1]
        return B

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_series_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
import pandas as pd
A, a, b = test_input
[insert]
result = B
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
import pandas as pd
A = pd.Series(np.random.randn(10,))
a = 2
b = 3
c = 4

B = ... # put solution in this variable

B = np.empty(len(A))
for k in range(0, len(B)):
    if k == 0:
        B[k] = a*A[k]
    elif k == 1:
        B[k] = a*A[k] + b*B[k-1]
    else:
        B[k] = a*A[k] + b*B[k-1] + c*B[k-2]

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(42)
            A = pd.Series(
                np.random.randn(
                    10,
                )
            )
            a = 2
            b = 3
            c = 4
        elif test_case_id == 2:
            np.random.seed(42)
            A = pd.Series(
                np.random.randn(
                    30,
                )
            )
            a, b, c = np.random.randint(2, 10, (3,))
        return A, a, b, c

    def generate_ans(data):
        _a = data
        A, a, b, c = _a
        B = np.empty(len(A))
        for k in range(0, len(B)):
            if k == 0:
                B[k] = a * A[k]
            elif k == 1:
                B[k] = a * A[k] + b * B[k - 1]
            else:
                B[k] = a * A[k] + b * B[k - 1] + c * B[k - 2]
        return B

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
import pandas as pd
A, a, b, c = test_input
[insert]
result = B
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

B = pd.Series(np.empty(len(A)))
for k in range(0, len(B)):
    if k == 0:
        B[k] = a*A[k]
    elif k == 1:
        B[k] = a*A[k] + b*B[k-1]
    else:
        B[k] = a*A[k] + b*B[k-1] + c*B[k-2]

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            np.random.seed(42)
            A = pd.Series(np.random.randn(10,))
            a = 2
            b = 3
            c = 4
        elif test_case_id == 2:
            np.random.seed(42)
            A = pd.Series(np.random.randn(30,))
            a, b, c = np.random.randint(2, 10, (3,))
        return A, a, b, c

    def generate_ans(data):
        _a = data
        A, a, b, c = _a
        B = pd.Series(np.empty(len(A)))
        for k in range(0, len(B)):
            if k == 0:
                B[k] = a * A[k]
            elif k == 1:
                B[k] = a * A[k] + b * B[k - 1]
            else:
                B[k] = a * A[k] + b * B[k - 1] + c * B[k - 2]
        return B

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_series_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
import pandas as pd
A, a, b, c = test_input
[insert]
result = B
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


result = np.ravel_multi_index(index, dims=dims, order='F')

import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            dims = (3, 4, 2)
            np.random.seed(42)
            a = np.random.rand(*dims)
            index = (1, 0, 1)
        elif test_case_id == 2:
            np.random.seed(42)
            dims = np.random.randint(8, 10, (5,))
            a = np.random.rand(*dims)
            index = np.random.randint(0, 7, (5,))
        return dims, a, index

    def generate_ans(data):
        _a = data
        dims, a, index = _a
        result = np.ravel_multi_index(index, dims=dims, order="F")
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
dims, a, index = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np

dims = (3, 4, 2)
a = np.random.rand(*dims)
index = (1, 0, 1)

result = ... # put solution in this variable

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            dims = (3, 4, 2)
            np.random.seed(42)
            a = np.random.rand(*dims)
            index = (1, 0, 1)
        elif test_case_id == 2:
            np.random.seed(42)
            dims = np.random.randint(8, 10, (5,))
            a = np.random.rand(*dims)
            index = np.random.randint(0, 7, (5,))
        return dims, a, index

    def generate_ans(data):
        _a = data
        dims, a, index = _a
        result = np.ravel_multi_index(index, dims=dims, order="F")
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
import pandas as pd
dims, a, index = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


subscripts = (1, 0, 1), array_shape = (3, 4, 2)

result = np.ravel_multi_index(index, dims=dims, order='C')

import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            dims = (3, 4, 2)
            np.random.seed(42)
            a = np.random.rand(*dims)
            index = (1, 0, 1)
        elif test_case_id == 2:
            np.random.seed(42)
            dims = np.random.randint(8, 10, (5,))
            a = np.random.rand(*dims)
            index = np.random.randint(0, 7, (5,))
        return dims, a, index

    def generate_ans(data):
        _a = data
        dims, a, index = _a
        result = np.ravel_multi_index(index, dims=dims, order="C")
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
dims, a, index = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

MultiIndex from product of [(0, 1, 2), ('a', 'b', 'c', 'd'), (True, False)], tuple (1, 'b', False)

import pandas as pd
import numpy as np

index = pd.MultiIndex.from_product([(0, 1, 2), ('a', 'b', 'c', 'd'), (True, False)])
tuple_index = (1, 'b', False)

result = ... # put solution in this variable

import pandas as pd
import numpy as np

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            index = pd.MultiIndex.from_product([(0, 1, 2), ('a', 'b', 'c', 'd'), (True, False)])
            tuple_index = (1, 'b', False)
        elif test_case_id == 2:
            index = pd.MultiIndex.from_product([range(3), list('abc'), [True, False]])
            tuple_index = (2, 'c', True)
        return index, tuple_index

    def generate_ans(data):
        index, tuple_index = data
        result = index.get_loc(tuple_index)
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(test_input)
    return test_input, expected_result

def test_execution(solution: str):
    exec_context = 'index, tuple_index = test_input\n[insert]\n'
    code = exec_context.replace('[insert]', solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {'test_input': test_input}
        exec(code, test_env)
        assert test_env['result'] == expected_result


values = np.zeros((2,3), dtype='int32,float32'); index = ['x', 'y']; columns = ['a','b','c']; df = pd.DataFrame(data=values, index=index, columns=columns)

import numpy as np
import pandas as pd
index = ['x', 'y']
columns = ['a','b','c']

df = ... # put solution in this variable

dtype = [('a','int32'), ('b','float32'), ('c','float32')]
values = np.zeros(2, dtype=dtype)
df = pd.DataFrame(values, index=index)

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            index = ["x", "y"]
            columns = ["a", "b", "c"]
        return index, columns

    def generate_ans(data):
        _a = data
        index, columns = _a
        dtype = [("a", "int32"), ("b", "float32"), ("c", "float32")]
        values = np.zeros(2, dtype=dtype)
        df = pd.DataFrame(values, index=index)
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_frame_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
import pandas as pd
index, columns = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import numpy as np
import pandas as pd
array = np.zeros((3, 3))
array[:, 0] = np.arange(3)


import numpy as np
a = np.arange(1,11)
index = np.array([0,1,0,0,0,1,1,2,2,1])

result = ... # put solution in this variable

uni = np.unique(index)
result = np.zeros(np.amax(index)+1)
for i in uni:
    result[i] = np.max(a[index==i])

import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.arange(1, 11)
            index = np.array([0, 1, 0, 0, 0, 1, 1, 2, 2, 1])
        elif test_case_id == 2:
            np.random.seed(42)
            index = np.random.randint(0, 5, (100,))
            a = np.random.randint(-100, 100, (100,))
        return a, index

    def generate_ans(data):
        _a = data
        a, index = _a
        uni = np.unique(index)
        result = np.zeros(np.amax(index) + 1)
        for i in uni:
            result[i] = np.max(a[index == i])
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
a, index = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
s = pd.Series(np.arange(1, 11))
groups = pd.Series([0, 1, 0, 0, 0, 1, 1, 2, 2, 1])

result = ... # put solution in this variable

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            s = pd.Series(np.arange(1, 11))
            groups = pd.Series([0, 1, 0, 0, 0, 1, 1, 2, 2, 1])
        elif test_case_id == 2:
            np.random.seed(42)
            groups = pd.Series(np.random.randint(0, 5, (100,)))
            s = pd.Series(np.random.randint(-100, 100, (100,)))
        return s, groups

    def generate_ans(data):
        s, groups = data
        result = s.groupby(groups).max()
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_series_equal(result, ans)
    return 1

exec_context = r"""
import pandas as pd
s, groups = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
a = np.arange(1,11)
index = np.array([0,1,0,0,0,-1,-1,2,2,1])

result = ... # put solution in this variable

add = np.max(index)
mask =index < 0
index[mask] += add+1
uni = np.unique(index)
result = np.zeros(np.amax(index)+1)
for i in uni:
    result[i] = np.min(a[index==i])

import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.arange(1, 11)
            index = np.array([0, 1, 0, 0, 0, -1, -1, 2, 2, 1])
        elif test_case_id == 2:
            np.random.seed(42)
            index = np.random.randint(-2, 5, (100,))
            a = np.random.randint(-100, 100, (100,))
        return a, index

    def generate_ans(data):
        _a = data
        a, index = _a
        add = np.max(index)
        mask = index < 0
        index[mask] += add + 1
        uni = np.unique(index)
        result = np.zeros(np.amax(index) + 1)
        for i in uni:
            result[i] = np.min(a[index == i])
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
a, index = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
s = pd.Series(np.arange(1,11))
index = pd.Series([0,1,0,0,0,-1,-1,2,2,1])

result = ... # put solution in this variable

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            s = pd.Series(np.arange(1, 11))
            index = pd.Series([0, 1, 0, 0, 0, -1, -1, 2, 2, 1])
        elif test_case_id == 2:
            np.random.seed(42)
            index = pd.Series(np.random.randint(-2, 5, (100,)))
            s = pd.Series(np.random.randint(-100, 100, (100,)))
        return s, index

    def generate_ans(data):
        _s = data
        s, index = _s
        add = np.max(index)
        mask = index < 0
        index[mask] += add + 1
        uni = np.unique(index)
        result = pd.Series(np.zeros(np.amax(index) + 1))
        for i in uni:
            result[i] = np.min(s[index == i])
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_series_equal(result, ans)
    return 1

exec_context = r"""
import pandas as pd
import numpy as np
s, index = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            x = [[2, 2, 2], [2, 2, 2], [2, 2, 2]]
            y = [[3, 3, 3], [3, 3, 3], [3, 3, 1]]
        elif test_case_id == 2:
            np.random.seed(42)
            dim1 = np.random.randint(5, 10)
            dim2 = np.random.randint(6, 10)
            x = np.random.rand(dim1, dim2)
            y = np.random.rand(dim1, dim2)
        return x, y

    def generate_ans(data):
        _a = data
        x, y = _a
        x_new = np.array(x)
        y_new = np.array(y)
        z = x_new + y_new
        return z

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
x, y = test_input
[insert]
result = z
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "while" not in tokens and "for" not in tokens

x = pd.DataFrame([[2, 2, 2], [2, 2, 2], [2, 2, 2]])
y = pd.DataFrame([[3, 3, 3], [3, 3, 3], [3, 3, 1]])
def elementwise_function(element_1, element_2):
    return (element_1 + element_2)

import pandas as pd
import numpy as np
x = pd.DataFrame([[2, 2, 2], [2, 2, 2], [2, 2, 2]])
y = pd.DataFrame([[3, 3, 3], [3, 3, 3], [3, 3, 1]])

z = ... # put solution in this variable

import pandas as pd
import numpy as np
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            x = pd.DataFrame([[2, 2, 2], [2, 2, 2], [2, 2, 2]])
            y = pd.DataFrame([[3, 3, 3], [3, 3, 3], [3, 3, 1]])
        elif test_case_id == 2:
            np.random.seed(42)
            dim1 = np.random.randint(5, 10)
            dim2 = np.random.randint(6, 10)
            x = pd.DataFrame(np.random.rand(dim1, dim2))
            y = pd.DataFrame(np.random.rand(dim1, dim2))
        return x, y

    def generate_ans(data):
        _a = data
        x, y = _a
        z = x + y
        return z

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_frame_equal(result, ans)
    return 1

exec_context = r"""
import pandas as pd
x, y = test_input
[insert]
result = z
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "while" not in tokens and "for" not in tokens


import numpy as np
probabilit = [0.333, 0.334, 0.333]
lista_elegir = [(3, 3), (3, 4), (3, 5)]
samples = 1000

result = ... # put solution in this variable

np.random.seed(42)
temp = np.array(lista_elegir)
result = temp[np.random.choice(len(lista_elegir),samples,p=probabilit)]

import numpy as np
import pandas as pd
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            probabilit = [0.333, 0.334, 0.333]
            lista_elegir = [(3, 3), (3, 4), (3, 5)]
            samples = 1000
        elif test_case_id == 2:
            np.random.seed(42)
            probabilit = np.zeros(10)
            probabilit[np.random.randint(0, 10)] = 1
            lista_elegir = [
                (x, y) for x, y in zip(np.arange(0, 10), np.arange(10, 0, -1))
            ]
            samples = 10
        return probabilit, lista_elegir, samples

    def generate_ans(data):
        _a = data
        probabilit, lista_elegir, samples = _a
        np.random.seed(42)
        temp = np.array(lista_elegir)
        result = temp[np.random.choice(len(lista_elegir), samples, p=probabilit)]
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    tuples = np.unique(ans, axis=0)
    for tuple in tuples:
        ratio = np.sum(np.all(result == tuple, axis=-1)) / result.shape[0]
        ans_ratio = np.sum(np.all(ans == tuple, axis=-1)) / ans.shape[0]
        assert abs(ratio - ans_ratio) <= 0.05
    return 1

exec_context = r"""
import numpy as np
probabilit, lista_elegir, samples = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "choice" in tokens

import pandas as pd
probabilit = [0.333, 0.333, 0.333]
df_elegir = pd.DataFrame([(3, 3), (3, 4), (3, 5)], columns=['A', 'B'])
samples = 1000
df_elegir.sample(n=samples, weights=probabilit)

import pandas as pd
import numpy as np
probabilit = [0.333, 0.334, 0.333]
df_elegir = pd.DataFrame([(3, 3), (3, 4), (3, 5)], columns=['A', 'B'])
samples = 1000

result = ... # put solution in this variable

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            probabilit = [0.333, 0.334, 0.333]
            df_elegir = pd.DataFrame([(3, 3), (3, 4), (3, 5)], columns=['A', 'B'])
            samples = 1000
        elif test_case_id == 2:
            np.random.seed(42)
            probabilit = np.zeros(10)
            probabilit[np.random.randint(0, 10)] = 1
            df_elegir = pd.DataFrame([(x, y) for x, y in zip(np.arange(0, 10), np.arange(10, 0, -1))], columns=['A', 'B'])
            samples = 10
        return probabilit, df_elegir, samples

    def generate_ans(data):
        _a = data
        probabilit, df_elegir, samples = _a
        np.random.seed(42)
        result = df_elegir.sample(n=samples, weights=probabilit, replace=True)
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def test_execution(solution: str):
    exec_context = 'import pandas as pd\nimport numpy as np\nprobabilit, df_elegir, samples = test_input\n[insert]\n'
    code = exec_context.replace('[insert]', solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {'test_input': test_input}
        exec(code, test_env)
        pd.testing.assert_frame_equal(test_env['result'], expected_result)


import numpy as np
a = np.ones((3, 3))
low_index = -1
high_index = 2

result = ... # put solution in this variable

def fill_crop(img, pos, crop):
    img_shape, pos, crop_shape = np.array(img.shape), np.array(pos), np.array(crop.shape),
    end = pos+crop_shape
    # Calculate crop slice positions
    crop_low = np.clip(0 - pos, a_min=0, a_max=crop_shape)
    crop_high = crop_shape - np.clip(end-img_shape, a_min=0, a_max=crop_shape)
    crop_slices = (slice(low, high) for low, high in zip(crop_low, crop_high))
    # Calculate img slice positions
    pos = np.clip(pos, a_min=0, a_max=img_shape)
    end = np.clip(end, a_min=0, a_max=img_shape)
    img_slices = (slice(low, high) for low, high in zip(pos, end))
    crop[tuple(crop_slices)] = img[tuple(img_slices)]
    return crop
result = fill_crop(a, [low_index, low_index], np.zeros((high_index-low_index, high_index-low_index)))

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.ones((3, 3))
            low_index = -1
            high_index = 2
        elif test_case_id == 2:
            a = np.ones((5, 5)) * 2
            low_index = 1
            high_index = 6
        elif test_case_id == 3:
            a = np.ones((5, 5))
            low_index = 2
            high_index = 7
        return a, low_index, high_index

    def generate_ans(data):
        _a = data
        a, low_index, high_index = _a

        def fill_crop(img, pos, crop):
            img_shape, pos, crop_shape = (
                np.array(img.shape),
                np.array(pos),
                np.array(crop.shape),
            )
            end = pos + crop_shape
            crop_low = np.clip(0 - pos, a_min=0, a_max=crop_shape)
            crop_high = crop_shape - np.clip(end - img_shape, a_min=0, a_max=crop_shape)
            crop_slices = (slice(low, high) for low, high in zip(crop_low, crop_high))
            pos = np.clip(pos, a_min=0, a_max=img_shape)
            end = np.clip(end, a_min=0, a_max=img_shape)
            img_slices = (slice(low, high) for low, high in zip(pos, end))
            crop[tuple(crop_slices)] = img[tuple(img_slices)]
            return crop

        result = fill_crop(
            a,
            [low_index, low_index],
            np.zeros((high_index - low_index, high_index - low_index)),
        )
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
a, low_index, high_index = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(3):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
df = pd.DataFrame(np.ones((3, 3)))
low_index = -1
high_index = 2

result = ... # put solution in this variable

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(np.ones((3, 3)))
            low_index = -1
            high_index = 2
        elif test_case_id == 2:
            df = pd.DataFrame(np.ones((5, 5)) * 2)
            low_index = 1
            high_index = 6
        elif test_case_id == 3:
            df = pd.DataFrame(np.ones((5, 5)))
            low_index = 2
            high_index = 7
        return df, low_index, high_index

    def generate_ans(data):
        df, low_index, high_index = data
        result = df.reindex(index=range(low_index, high_index), columns=range(low_index, high_index)).fillna(0)
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_frame_equal(result, ans)
    return 1

exec_context = r"""
import pandas as pd
import numpy as np
df, low_index, high_index = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(3):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
import pandas as pd
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            x = np.array(
                [-2, -1.4, -1.1, 0, 1.2, 2.2, 3.1, 4.4, 8.3, 9.9, 10, 14, 16.2]
            )
        elif test_case_id == 2:
            np.random.seed(42)
            x = np.random.rand(10) - 0.5
        return x

    def generate_ans(data):
        _a = data
        x = _a
        result = x[x >= 0]
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
x = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "while" not in tokens and "for" not in tokens

import pandas as pd
import numpy as np
s = pd.Series([-2, -1.4, -1.1, 0, 1.2, 2.2, 3.1, 4.4, 8.3, 9.9, 10, 14, 16.2])

result = ... # put solution in this variable

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            s = pd.Series([-2, -1.4, -1.1, 0, 1.2, 2.2, 3.1, 4.4, 8.3, 9.9, 10, 14, 16.2])
        elif test_case_id == 2:
            np.random.seed(42)
            s = pd.Series(np.random.rand(10) - 0.5)
        return s

    def generate_ans(data):
        _a = data
        s = _a
        result = s[s >= 0]
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def test_execution(solution: str):
    code = 'import pandas as pd\ns = test_input\n' + solution
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {'test_input': test_input}
        exec(code, test_env)
        assert test_env['result'].equals(expected_result)


import numpy as np
data = np.array([4, 2, 5, 6, 7, 5, 4, 3, 5, 7])
bin_size = 3

bin_data_max = ... # put solution in this variable

bin_data_max = data[:(data.size // bin_size) * bin_size].reshape(-1, bin_size).max(axis=1)

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([4, 2, 5, 6, 7, 5, 4, 3, 5, 7])
            width = 3
        elif test_case_id == 2:
            np.random.seed(42)
            data = np.random.rand(np.random.randint(5, 10))
            width = 4
        return data, width

    def generate_ans(data):
        _a = data
        data, bin_size = _a
        bin_data_max = (
            data[: (data.size // bin_size) * bin_size].reshape(-1, bin_size).max(axis=1)
        )
        return bin_data_max

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_allclose(result, ans, atol=1e-2)
    return 1

exec_context = r"""
import numpy as np
data, bin_size = test_input
[insert]
result = bin_data_max
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
data = pd.Series([4, 2, 5, 6, 7, 5, 4, 3, 5, 7])
bin_size = 3

bin_data_max = ... # put solution in this variable

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = pd.Series([4, 2, 5, 6, 7, 5, 4, 3, 5, 7])
            width = 3
        elif test_case_id == 2:
            np.random.seed(42)
            data = pd.Series(np.random.rand(np.random.randint(5, 10)))
            width = 4
        return data, width

    def generate_ans(data):
        _a = data
        data, bin_size = _a
        bin_data_max = data.groupby(data.index // bin_size).max()
        return bin_data_max

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_series_equal(result, ans)
    return 1

exec_context = r"""
import pandas as pd
data, bin_size = test_input
[insert]
result = bin_data_max
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
data = np.array([4, 2, 5, 6, 7, 5, 4, 3, 5, 7])
bin_size = 3

bin_data_mean = ... # put solution in this variable

new_data = data[::-1]
bin_data_mean = new_data[:(data.size // bin_size) * bin_size].reshape(-1, bin_size).mean(axis=1)

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([4, 2, 5, 6, 7, 5, 4, 3, 5, 7])
            width = 3
        elif test_case_id == 2:
            np.random.seed(42)
            data = np.random.rand(np.random.randint(5, 10))
            width = 4
        return data, width

    def generate_ans(data):
        _a = data
        data, bin_size = _a
        new_data = data[::-1]
        bin_data_mean = (
            new_data[: (data.size // bin_size) * bin_size]
            .reshape(-1, bin_size)
            .mean(axis=1)
        )
        return bin_data_mean

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_allclose(result, ans, atol=1e-2)
    return 1

exec_context = r"""
import numpy as np
data, bin_size = test_input
[insert]
result = bin_data_mean
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
data = pd.Series([4, 2, 5, 6, 7, 5, 4, 3, 5, 7])
bin_size = 3

bin_data_mean = ... # put solution in this variable

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = pd.Series([4, 2, 5, 6, 7, 5, 4, 3, 5, 7])
            width = 3
        elif test_case_id == 2:
            np.random.seed(42)
            data = pd.Series(np.random.rand(np.random.randint(5, 10)))
            width = 4
        return data, width

    def generate_ans(data):
        _a = data
        data, bin_size = _a
        new_data = data.iloc[::-1]
        bin_data_mean = new_data.iloc[:(data.size // bin_size) * bin_size].values.reshape(-1, bin_size).mean(axis=1)
        return bin_data_mean

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_allclose(result, ans, atol=1e-2)
    return 1

exec_context = r"""
import pandas as pd
data, bin_size = test_input
[insert]
result = bin_data_mean
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
data = np.array([[4, 2, 5, 6, 7],
[ 5, 4, 3, 5, 7]])
bin_size = 3

bin_data_mean = ... # put solution in this variable

new_data = data[:, ::-1]
bin_data_mean = new_data[:,:(data.shape[1] // bin_size) * bin_size].reshape(data.shape[0], -1, bin_size).mean(axis=-1)[:,::-1]

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([[4, 2, 5, 6, 7], [5, 4, 3, 5, 7]])
            width = 3
        elif test_case_id == 2:
            np.random.seed(42)
            data = np.random.rand(np.random.randint(5, 10), np.random.randint(6, 10))
            width = np.random.randint(2, 4)
        return data, width

    def generate_ans(data):
        _a = data
        data, bin_size = _a
        new_data = data[:, ::-1]
        bin_data_mean = (
            new_data[:, : (data.shape[1] // bin_size) * bin_size]
            .reshape(data.shape[0], -1, bin_size)
            .mean(axis=-1)[:, ::-1]
        )
        return bin_data_mean

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_allclose(result, ans, atol=1e-2)
    return 1

exec_context = r"""
import numpy as np
data, bin_size = test_input
[insert]
result = bin_data_mean
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
data = pd.DataFrame({
    'A': [4, 2, 5, 6, 7],
    'B': [5, 4, 3, 5, 7]
}).T
bin_size = 3

bin_data_mean = ... # put solution in this variable

new_data = data.iloc[:, ::-1]
bin_data_mean = new_data.iloc[:,:(data.shape[1] // bin_size) * bin_size].apply(lambda x: x.values.reshape(-1, bin_size).mean(axis=1), axis=1).apply(pd.Series).iloc[:,::-1]

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = pd.DataFrame({
                'A': [4, 2, 5, 6, 7],
                'B': [5, 4, 3, 5, 7]
            }).T
            width = 3
        elif test_case_id == 2:
            np.random.seed(42)
            data = pd.DataFrame(np.random.rand(np.random.randint(5, 10), np.random.randint(6, 10))).T
            width = np.random.randint(2, 4)
        return data, width

    def generate_ans(data):
        _a = data
        data, bin_size = _a
        new_data = data.iloc[:, ::-1]
        bin_data_mean = (
            new_data.iloc[:, : (data.shape[1] // bin_size) * bin_size]
            .apply(lambda x: x.values.reshape(-1, bin_size).mean(axis=1), axis=1)
            .apply(pd.Series)
            .iloc[:, ::-1]
        )
        return bin_data_mean

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_frame_equal(result, ans, check_dtype=False)
    return 1

exec_context = r"""
import pandas as pd
data, bin_size = test_input
[insert]
result = bin_data_mean
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
x = 0.25
x_min = 0
x_max = 1

define function named `smoothclamp` as solution

def smoothclamp(x):
    return np.where(x < x_min, x_min, np.where(x > x_max, x_max, 3*x**2 - 2*x**3))

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            x = 0.25
            x_min = 0
            x_max = 1
        elif test_case_id == 2:
            x = -1
            x_min = 0
            x_max = 1
        elif test_case_id == 3:
            x = 2
            x_min = 0
            x_max = 1
        return x, x_min, x_max

    def generate_ans(data):
        _a = data
        x, x_min, x_max = _a

        def smoothclamp(x):
            return np.where(
                x < x_min, x_min, np.where(x > x_max, x_max, 3 * x**2 - 2 * x**3)
            )

        result = smoothclamp(x)
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    assert abs(ans - result) <= 1e-5
    return 1

exec_context = r"""
import numpy as np
x, x_min, x_max = test_input
[insert]
result = smoothclamp(x)
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(3):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import numpy as np
import pandas as pd
x = pd.Series([0.25])
x_min = 0
x_max = 1

define function named `smoothclamp` as solution

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            x = pd.Series([0.25])
            x_min = 0
            x_max = 1
        elif test_case_id == 2:
            x = pd.Series([-1])
            x_min = 0
            x_max = 1
        elif test_case_id == 3:
            x = pd.Series([2])
            x_min = 0
            x_max = 1
        return x, x_min, x_max

    def generate_ans(data):
        _a = data
        x, x_min, x_max = _a

        def smoothclamp(x):
            return np.where(x < x_min, x_min, np.where(x > x_max, x_max, 3 * x**2 - 2 * x**3))

        result = smoothclamp(x)
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    assert abs(ans - result) <= 1e-5
    return 1

exec_context = r"""
import numpy as np
import pandas as pd
x, x_min, x_max = test_input
[insert]
result = smoothclamp(x)
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(3):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
x = 0.25
x_min = 0
x_max = 1
N = 5

define function named `smoothclamp` as solution

import numpy as np
import copy
import scipy
from scipy.special import comb

def generate_test_case(test_case_id):

    def define_test_input(test_case_id):
        if test_case_id == 1:
            x = 0.25
            x_min = 0
            x_max = 1
            N = 5
        elif test_case_id == 2:
            x = 0.25
            x_min = 0
            x_max = 1
            N = 8
        elif test_case_id == 3:
            x = -1
            x_min = 0
            x_max = 1
            N = 5
        elif test_case_id == 4:
            x = 2
            x_min = 0
            x_max = 1
            N = 7
        return x, x_min, x_max, N

    def generate_ans(data):
        _a = data
        x, x_min, x_max, N = _a

        def smoothclamp(x, x_min=0, x_max=1, N=1):
            if x < x_min:
                return x_min
            if x > x_max:
                return x_max
            x = np.clip((x - x_min) / (x_max - x_min), 0, 1)
            result = 0
            for n in range(0, N + 1):
                result += comb(N + n, n) * comb(2 * N + 1, N - n) * (-x) ** n
            result *= x ** (N + 1)
            return result

        result = smoothclamp(x, N=N)
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))

    return test_input, expected_result

def exec_test(result, ans):
    assert abs(ans - result) <= 1e-5
    return 1

exec_context = r"""
import numpy as np
x, x_min, x_max, N = test_input
[insert]
result = smoothclamp(x, N=N)
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(4):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
x = 0.25
x_min = 0
x_max = 1
N = 5

# Define function named `smoothclamp` as solution

import pandas as pd
import numpy as np
from scipy.special import comb

def smoothclamp(x, x_min=0, x_max=1, N=1):
    if x < x_min:
        return x_min
    if x > x_max:
        return x_max
    x = np.clip((x - x_min) / (x_max - x_min), 0, 1)

    result = 0
    for n in range(0, N + 1):
        result += comb(N + n, n) * comb(2 * N + 1, N - n) * (-x) ** n

    result *= x ** (N + 1)
    return result

import pandas as pd
import numpy as np
import copy
from scipy.special import comb

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            x = 0.25
            x_min = 0
            x_max = 1
            N = 5
        elif test_case_id == 2:
            x = 0.25
            x_min = 0
            x_max = 1
            N = 8
        elif test_case_id == 3:
            x = -1
            x_min = 0
            x_max = 1
            N = 5
        elif test_case_id == 4:
            x = 2
            x_min = 0
            x_max = 1
            N = 7
        return x, x_min, x_max, N

    def generate_ans(data):
        _a = data
        x, x_min, x_max, N = _a

        def smoothclamp(x, x_min=0, x_max=1, N=1):
            if x < x_min:
                return x_min
            if x > x_max:
                return x_max
            x = np.clip((x - x_min) / (x_max - x_min), 0, 1)
            result = 0
            for n in range(0, N + 1):
                result += comb(N + n, n) * comb(2 * N + 1, N - n) * (-x) ** n
            result *= x ** (N + 1)
            return result

        result = smoothclamp(x, N=N)
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))

    return test_input, expected_result

def exec_test(result, ans):
    assert abs(ans - result) <= 1e-5
    return 1

exec_context = r"""
import numpy as np
x, x_min, x_max, N = test_input
[insert]
result = smoothclamp(x, N=N)
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(4):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
a = np.array([1,2,3,4])
b = np.array([5, 4, 3, 2])

result = ... # put solution in this variable

result = np.correlate(a, np.hstack((b[1:], b)), mode='valid')

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array([1, 2, 3, 4])
            b = np.array([5, 4, 3, 2])
        elif test_case_id == 2:
            np.random.seed(42)
            a = np.random.rand(50)
            b = np.random.rand(50)
        return a, b

    def generate_ans(data):
        _a = data
        a, b = _a
        result = np.correlate(a, np.hstack((b[1:], b)), mode="valid")
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_allclose(result, ans)
    return 1

exec_context = r"""
import numpy as np
a, b = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
a = pd.Series([1,2,3,4])
b = pd.Series([5, 4, 3, 2])

result = ... # put solution in this variable

result = np.correlate(a, pd.concat([b[1:], b]), mode='valid')

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = pd.Series([1, 2, 3, 4])
            b = pd.Series([5, 4, 3, 2])
        elif test_case_id == 2:
            np.random.seed(42)
            a = pd.Series(np.random.rand(50))
            b = pd.Series(np.random.rand(50))
        return a, b

    def generate_ans(data):
        _a = data
        a, b = _a
        result = np.correlate(a, pd.concat([b[1:], b]), mode="valid")
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_allclose(result, ans)
    return 1

exec_context = r"""
import pandas as pd
import numpy as np
a, b = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
a = np.array([0, 1, 2, 5, 6, 7, 8, 8, 8, 10, 29, 32, 45])

result = ... # put solution in this variable

result = (a.mean()-3*a.std(), a.mean()+3*a.std())

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array([0, 1, 2, 5, 6, 7, 8, 8, 8, 10, 29, 32, 45])
        elif test_case_id == 2:
            np.random.seed(42)
            a = np.random.randn(30)
        return a

    def generate_ans(data):
        _a = data
        a = _a
        result = (a.mean() - 3 * a.std(), a.mean() + 3 * a.std())
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_allclose(result, ans)
    return 1

exec_context = r"""
import numpy as np
a = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
s = pd.Series([0, 1, 2, 5, 6, 7, 8, 8, 8, 10, 29, 32, 45])

result = ... # put solution in this variable

result = (s.mean()-3*s.std(), s.mean()+3*s.std())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            s = pd.Series([0, 1, 2, 5, 6, 7, 8, 8, 8, 10, 29, 32, 45])
        elif test_case_id == 2:
            np.random.seed(42)
            s = pd.Series(np.random.randn(30))
        return s

    def generate_ans(data):
        _s = data
        s = _s
        result = (s.mean() - 3 * s.std(), s.mean() + 3 * s.std())
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_allclose(result, ans)
    return 1

exec_context = r"""
import pandas as pd
s = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


result = (a.mean()-2*a.std(), a.mean()+2*a.std())

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array([0, 1, 2, 5, 6, 7, 8, 8, 8, 10, 29, 32, 45])
        elif test_case_id == 2:
            np.random.seed(42)
            a = np.random.randn(30)
        return a

    def generate_ans(data):
        _a = data
        a = _a
        result = (a.mean() - 2 * a.std(), a.mean() + 2 * a.std())
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_allclose(result, ans)
    return 1

exec_context = r"""
import numpy as np
a = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

result = (s.mean()-2*s.std(), s.mean()+2*s.std())

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            s = pd.Series([0, 1, 2, 5, 6, 7, 8, 8, 8, 10, 29, 32, 45])
        elif test_case_id == 2:
            np.random.seed(42)
            s = pd.Series(np.random.randn(30))
        return s

    def generate_ans(data):
        _s = data
        s = _s
        result = (s.mean() - 2 * s.std(), s.mean() + 2 * s.std())
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_allclose(result, ans)
    return 1

exec_context = r"""
import pandas as pd
s = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
example_a = np.array([0, 1, 2, 5, 6, 7, 8, 8, 8, 10, 29, 32, 45])
def f(a = example_a):
    # return the solution in this function
    # result = f(a)
    ###

    result = (a.mean()-3*a.std(), a.mean()+3*a.std())

    return result

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array([0, 1, 2, 5, 6, 7, 8, 8, 8, 10, 29, 32, 45])
        elif test_case_id == 2:
            np.random.seed(42)
            a = np.random.randn(30)
        return a

    def generate_ans(data):
        _a = data
        a = _a
        result = (a.mean() - 3 * a.std(), a.mean() + 3 * a.std())
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_allclose(result, ans)
    return 1

exec_context = r"""
import numpy as np
a = test_input
def f(a):
[insert]
result = f(a)
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
example_s = pd.Series([0, 1, 2, 5, 6, 7, 8, 8, 8, 10, 29, 32, 45])
def f(s = example_s):
    # return the solution in this function
    # result = f(s)
    ###

    result = (s.mean()-3*s.std(), s.mean()+3*s.std())

    return result

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            s = pd.Series([0, 1, 2, 5, 6, 7, 8, 8, 8, 10, 29, 32, 45])
        elif test_case_id == 2:
            np.random.seed(42)
            s = pd.Series(np.random.randn(30))
        return s

    def generate_ans(data):
        _s = data
        s = _s
        result = (s.mean() - 3 * s.std(), s.mean() + 3 * s.std())
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_allclose(result, ans)
    return 1

exec_context = r"""
import pandas as pd
s = test_input
def f(s):
[insert]
result = f(s)
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


interval = (a.mean()-2*a.std(), a.mean()+2*a.std())
result = ~np.logical_and(a>interval[0], a<interval[1])

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array([0, 1, 2, 5, 6, 7, 8, 8, 8, 10, 29, 32, 45])
        elif test_case_id == 2:
            np.random.seed(42)
            a = np.random.randn(30)
        elif test_case_id == 3:
            a = np.array([-1, -2, -10, 0, 1, 2, 2, 3])
        return a

    def generate_ans(data):
        _a = data
        a = _a
        interval = (a.mean() - 2 * a.std(), a.mean() + 2 * a.std())
        result = ~np.logical_and(a > interval[0], a < interval[1])
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
a = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(3):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

interval = (s.mean()-2*s.std(), s.mean()+2*s.std())
result = ~np.logical_and(s>interval[0], s<interval[1])

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            s = pd.Series([0, 1, 2, 5, 6, 7, 8, 8, 8, 10, 29, 32, 45])
        elif test_case_id == 2:
            np.random.seed(42)
            s = pd.Series(np.random.randn(30))
        elif test_case_id == 3:
            s = pd.Series([-1, -2, -10, 0, 1, 2, 2, 3])
        return s

    def generate_ans(data):
        _s = data
        s = _s
        interval = (s.mean() - 2 * s.std(), s.mean() + 2 * s.std())
        result = ~np.logical_and(s > interval[0], s < interval[1])
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_series_equal(result, ans)
    return 1

exec_context = r"""
import pandas as pd
import numpy as np
s = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(3):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


DataArray = np.array([[value, value...]], dtype=float32); masked_data = ma.masked_where(DataArray < 0, DataArray); percentile = 5

import numpy as np
DataArray = np.arange(-5.5, 10.5)
percentile = 50

prob = ... # put solution in this variable

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.arange(-5.5, 10.5)
            percentile = 50
        elif test_case_id == 2:
            np.random.seed(42)
            a = np.random.rand(50) - 0.5
            percentile = np.random.randint(1, 100)
        return a, percentile

    def generate_ans(data):
        _a = data
        DataArray, percentile = _a
        mdata = np.ma.masked_where(DataArray < 0, DataArray)
        mdata = np.ma.filled(mdata, np.nan)
        prob = np.nanpercentile(mdata, percentile)
        return prob

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_allclose(result, ans)
    return 1

exec_context = r"""
import numpy as np
DataArray, percentile = test_input
[insert]
result = prob
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
DataArray = pd.Series(np.arange(-5.5, 10.5))
percentile = 50

prob = ... # put solution in this variable

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = pd.Series(np.arange(-5.5, 10.5))
            percentile = 50
        elif test_case_id == 2:
            np.random.seed(42)
            a = pd.Series(np.random.rand(50) - 0.5)
            percentile = np.random.randint(1, 100)
        return a, percentile

    def generate_ans(data):
        _a = data
        DataArray, percentile = _a
        mdata = DataArray[DataArray >= 0]
        prob = mdata.quantile(percentile/100)
        return prob

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_allclose(result, ans)
    return 1

exec_context = r"""
import pandas as pd
DataArray, percentile = test_input
[insert]
result = prob
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
a = np.array([[0, 3, 1, 3], [3, 0, 0, 0], [1, 0, 0, 0], [3, 0, 0, 0]])
zero_rows = 0
zero_cols = 0

a = ... # put solution in this variable

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array([[0, 3, 1, 3], [3, 0, 0, 0], [1, 0, 0, 0], [3, 0, 0, 0]])
            zero_rows = 0
            zero_cols = 0
        return a, zero_rows, zero_cols

    def generate_ans(data):
        _a = data
        a, zero_rows, zero_cols = _a
        a[zero_rows, :] = 0
        a[:, zero_cols] = 0
        return a

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
a, zero_rows, zero_cols = test_input
[insert]
result = a
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
df = pd.DataFrame([[0, 3, 1, 3], [3, 0, 0, 0], [1, 0, 0, 0], [3, 0, 0, 0]])
zero_rows = 0
zero_cols = 0

df = ... # put solution in this variable

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame([[0, 3, 1, 3], [3, 0, 0, 0], [1, 0, 0, 0], [3, 0, 0, 0]])
            zero_rows = 0
            zero_cols = 0
        return df, zero_rows, zero_cols

    def generate_ans(data):
        _df = data
        df, zero_rows, zero_cols = _df
        df.iloc[zero_rows, :] = 0
        df.iloc[:, zero_cols] = 0
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_frame_equal(result, ans)
    return 1

exec_context = r"""
import pandas as pd
import numpy as np
df, zero_rows, zero_cols = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
a = np.array([[0, 3, 1, 3], [3, 0, 0, 0], [1, 0, 0, 0], [3, 0, 0, 0]])
zero_rows = [1, 3]
zero_cols = [1, 2]

a = ... # put solution in this variable

import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array([[0, 3, 1, 3], [3, 0, 0, 0], [1, 0, 0, 0], [3, 0, 0, 0]])
            zero_rows = [1, 3]
            zero_cols = [1, 2]
        return a, zero_rows, zero_cols

    def generate_ans(data):
        _a = data
        a, zero_rows, zero_cols = _a
        a[zero_rows, :] = 0
        a[:, zero_cols] = 0
        return a

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
a, zero_rows, zero_cols = test_input
[insert]
result = a
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
df = pd.DataFrame([[0, 3, 1, 3], [3, 0, 0, 0], [1, 0, 0, 0], [3, 0, 0, 0]])
zero_rows = [1, 3]
zero_cols = [1, 2]

df = ... # put solution in this variable

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame([[0, 3, 1, 3], [3, 0, 0, 0], [1, 0, 0, 0], [3, 0, 0, 0]])
            zero_rows = [1, 3]
            zero_cols = [1, 2]
        return df, zero_rows, zero_cols

    def generate_ans(data):
        _df = data
        df, zero_rows, zero_cols = _df
        df.iloc[zero_rows, :] = 0
        df.iloc[:, zero_cols] = 0
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_frame_equal(result, ans)
    return 1

exec_context = r"""
import pandas as pd
import numpy as np
df, zero_rows, zero_cols = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
import pandas as pd
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array([[0, 3, 1, 3], [3, 0, 0, 0], [1, 0, 0, 0], [3, 0, 0, 0]])
        elif test_case_id == 2:
            a = np.array([[5, 3, 1, 3], [3, 1, 2, 0], [1, 0, 0, 0], [3, 0, 0, 0]])
        return a

    def generate_ans(data):
        _a = data
        a = _a
        a[1, :] = 0
        a[:, 0] = 0
        return a

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
a = test_input
[insert]
result = a
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
df = pd.DataFrame([[0, 3, 1, 3], [3, 0, 0, 0], [1, 0, 0, 0], [3, 0, 0, 0]])

df = ... # put solution in this variable

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame([[0, 3, 1, 3], [3, 0, 0, 0], [1, 0, 0, 0], [3, 0, 0, 0]])
        elif test_case_id == 2:
            df = pd.DataFrame([[5, 3, 1, 3], [3, 1, 2, 0], [1, 0, 0, 0], [3, 0, 0, 0]])
        return df

    def generate_ans(data):
        _df = data
        df = _df
        df.iloc[1, :] = 0
        df.iloc[:, 0] = 0
        return df

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_frame_equal(result, ans)
    return 1

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = df
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
a = np.array([[0, 1], [2, 1], [4, 8]])

mask = ... # put solution in this variable

import numpy as np
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array([[0, 1], [2, 1], [4, 8]])
        elif test_case_id == 2:
            np.random.seed(42)
            a = np.random.rand(10, 5)
        return a

    def generate_ans(data):
        _a = data
        a = _a
        mask = a.max(axis=1, keepdims=1) == a
        return mask

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
a = test_input
[insert]
result = mask
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "while" not in tokens and "for" not in tokens

import pandas as pd
import numpy as np
df = pd.DataFrame({'A': [0, 2, 4], 'B': [1, 1, 8]})

mask = ... # put solution in this variable

import pandas as pd
import numpy as np
import copy
import tokenize, io

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame({'A': [0, 2, 4], 'B': [1, 1, 8]})
        elif test_case_id == 2:
            np.random.seed(42)
            df = pd.DataFrame(np.random.rand(10, 5), columns=list('ABCDE'))
        return df

    def generate_ans(data):
        _df = data
        df = _df
        mask = df.eq(df.max(axis=1), axis=0)
        return mask

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_frame_equal(result, ans)
    return 1

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = mask
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

def test_string(solution: str):
    tokens = []
    for token in tokenize.tokenize(io.BytesIO(solution.encode("utf-8")).readline):
        tokens.append(token.string)
    assert "while" not in tokens and "for" not in tokens


import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            a = np.array([[0, 1], [2, 1], [4, 8]])
        elif test_case_id == 2:
            np.random.seed(42)
            a = np.random.rand(10, 5)
        return a

    def generate_ans(data):
        _a = data
        a = _a
        mask = a.min(axis=1, keepdims=1) == a
        return mask

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
a = test_input
[insert]
result = mask
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame({'A': [0, 2, 4], 'B': [1, 1, 8]})
        elif test_case_id == 2:
            np.random.seed(42)
            data = np.random.rand(10, 5)
            df = pd.DataFrame(data, columns=[f'Col{i}' for i in range(5)])
        return df

    def generate_ans(data):
        _df = data
        df = _df
        mask = df.eq(df.min(axis=1), axis=0)
        return mask

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    pd.testing.assert_frame_equal(result, ans)
    return 1

exec_context = r"""
import pandas as pd
import numpy as np
df = test_input
[insert]
result = mask
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(2):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)


import numpy as np
post = [2, 5, 6, 10]
distance = [50, 100, 500, 1000]

result = ... # put solution in this variable

import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            post = [2, 5, 6, 10]
            distance = [50, 100, 500, 1000]
        return post, distance

    def generate_ans(data):
        _a = data
        post, distance = _a
        result = np.corrcoef(post, distance)[0][1]
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    assert np.allclose(result, ans)
    return 1

exec_context = r"""
import numpy as np
post, distance = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)

import pandas as pd
import numpy as np
post = pd.Series([2, 5, 6, 10])
distance = pd.Series([50, 100, 500, 1000])

result = ... # put solution in this variable

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def define_test_input(test_case_id):
        if test_case_id == 1:
            post = pd.Series([2, 5, 6, 10])
            distance = pd.Series([50, 100, 500, 1000])
        return post, distance

    def generate_ans(data):
        _a = data
        post, distance = _a
        result = post.corr(distance)
        return result

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input))
    return test_input, expected_result

def exec_test(result, ans):
    assert np.allclose(result, ans)
    return 1

exec_context = r"""
import pandas as pd
post, distance = test_input
[insert]
"""

def test_execution(solution: str):
    code = exec_context.replace("[insert]", solution)
    for i in range(1):
        test_input, expected_result = generate_test_case(i + 1)
        test_env = {"test_input": test_input}
        exec(code, test_env)
        assert exec_test(test_env["result"], expected_result)