import numpy as np
a = np.ones((41, 12))
shape = (93, 13)

result = ... # put solution in this variable

def to_shape(a, shape):
    y_, x_ = shape
    y, x = a.shape
    y_pad = (y_-y)
    x_pad = (x_-x)
    return np.pad(a,((y_pad//2, y_pad//2 + y_pad%2),
                        (x_pad//2, x_pad//2 + x_pad%2)),
                    mode = 'constant')
result = to_shape(a, shape)

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((41, 12))
            shape = (93, 13)
        elif test_case_id == 2:
            a = np.ones((41, 13))
            shape = (93, 13)
        elif test_case_id == 3:
            a = np.ones((93, 11))
            shape = (93, 13)
        elif test_case_id == 4:
            a = np.ones((42, 10))
            shape = (93, 13)
        return a, shape

    def generate_ans(data):
        _a = data
        a, shape = _a

        def to_shape(a, shape):
            y_, x_ = shape
            y, x = a.shape
            y_pad = y_ - y
            x_pad = x_ - x
            return np.pad(
                a,
                (
                    (y_pad // 2, y_pad // 2 + y_pad % 2),
                    (x_pad // 2, x_pad // 2 + x_pad % 2),
                ),
                mode="constant",
            )

        result = to_shape(a, shape)
        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, shape = test_input
[insert]
"""

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
df = pd.DataFrame({'A': np.ones(41)})
max_length = 93

result = ... # 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({'A': np.ones(41)})
            max_length = 93
        elif test_case_id == 2:
            df = pd.DataFrame({'A': np.ones(41)})
            max_length = 93
        elif test_case_id == 3:
            df = pd.DataFrame({'A': np.ones(93)})
            max_length = 93
        elif test_case_id == 4:
            df = pd.DataFrame({'A': np.ones(42)})
            max_length = 93
        return df, max_length

    def generate_ans(data):
        df, max_length = data
        def to_length(df, max_length):
            length_diff = max_length - len(df)
            pad_top = length_diff // 2
            pad_bottom = length_diff - pad_top
            padding = pd.DataFrame(0, index=np.arange(pad_top), columns=df.columns)
            df = pd.concat([padding, df, padding], ignore_index=True)
            if pad_bottom > pad_top:
                df = pd.concat([df, pd.DataFrame(0, index=[max_length-1], columns=df.columns)], ignore_index=True)
            return df

        result = to_length(df, max_length)
        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, max_length = test_input
[insert]
"""

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)


n = 12
np.array([i for i in range(0, 12)])

import numpy as np
a = np.arange(12)

a = ... # 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:
            a = np.arange(12)
        elif test_case_id == 2:
            np.random.seed(42)
            n = np.random.randint(15, 20)
            a = np.random.rand(3 * n)
        return a

    def generate_ans(data):
        _a = data
        a = _a
        a = a.reshape(-1, 3)
        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
a = pd.Series(np.arange(12))

a = ... # 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:
            a = pd.Series(np.arange(12))
        elif test_case_id == 2:
            np.random.seed(42)
            n = np.random.randint(15, 20)
            a = pd.Series(np.random.rand(3 * n))
        return a

    def generate_ans(data):
        _a = data
        a = _a.to_frame().values.reshape(-1, 3)
        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 pandas as pd
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 numpy as np
import pandas as pd
data = {'a': [1, 2, 3, 4, 5], 'b': [2, -6, 0, -4, 100]}
df = pd.DataFrame(data)

result = ... # put solution in this variable

result = np.where((df.a<= 4)&(df.a>1), df.b,np.nan)

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 = {"a": [1, 2, 3, 4, 5], "b": [2, -6, 0, -4, 100]}
            df = pd.DataFrame(data)
        return data, df

    def generate_ans(data):
        _a = data
        data, df = _a
        result = np.where((df.a <= 4) & (df.a > 1), df.b, np.nan)
        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
data, df = 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
data = {'a': [1, 2, 3, 4, 5], 'b': [2, -6, 0, -4, 100]}
df = pd.DataFrame(data)

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:
            data = {'a': [1, 2, 3, 4, 5], 'b': [2, -6, 0, -4, 100]}
            df = pd.DataFrame(data)
        return data, df

    def generate_ans(data):
        _a = data
        data, df = _a
        result = df['b'].where((df['a'] > 1) & (df['a'] <= 4))
        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
data, df = 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)


mask = im == 0
rows = np.flatnonzero((~mask).sum(axis=1))
cols = np.flatnonzero((~mask).sum(axis=0))
if rows.shape[0] == 0:
    result = np.array([])
else:
    result = im[rows.min():rows.max()+1, cols.min():cols.max()+1]

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:
            im = np.array(
                [
                    [0, 0, 0, 0, 0, 0],
                    [0, 0, 5, 1, 2, 0],
                    [0, 1, 8, 0, 1, 0],
                    [0, 0, 0, 7, 1, 0],
                    [0, 0, 0, 0, 0, 0],
                ]
            )
        elif test_case_id == 2:
            np.random.seed(42)
            im = np.random.randint(0, 10, (10, 12))
            im[:, 0] = 0
            im[-1, :] = 0
        elif test_case_id == 3:
            im = np.zeros((10, 10))
        return im

    def generate_ans(data):
        _a = data
        im = _a
        mask = im == 0
        rows = np.flatnonzero((~mask).sum(axis=1))
        cols = np.flatnonzero((~mask).sum(axis=0))
        if rows.shape[0] == 0:
            result = np.array([])
        else:
            result = im[rows.min() : rows.max() + 1, cols.min() : cols.max() + 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):
    if ans.shape[0]:
        np.testing.assert_array_equal(result, ans)
    else:
        ans = ans.reshape(0)
        result = result.reshape(0)
        np.testing.assert_array_equal(result, ans)
    return 1

exec_context = r"""
import numpy as np
im = 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)

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
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,0,0,0,0,0], [0,0,5,1,2,0], [0,1,8,0,1,0], [0,0,0,7,1,0], [0,0,0,0,0,0]])
        elif test_case_id == 2:
            np.random.seed(42)
            data = np.random.randint(0, 10, (10, 12))
            data[:, 0] = 0
            data[-1, :] = 0
            df = pd.DataFrame(data)
        elif test_case_id == 3:
            df = pd.DataFrame(np.zeros((10, 10)))
        return df

    def generate_ans(data):
        df = data
        mask = df == 0
        rows = np.flatnonzero((~mask).sum(axis=1))
        cols = np.flatnonzero((~mask).sum(axis=0))
        if rows.shape[0] == 0:
            result = pd.DataFrame()
        else:
            result = df.iloc[rows.min():rows.max()+1, cols.min():cols.max()+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 test_execution(solution: str):
    exec_context = 'import pandas as pd\nimport numpy as np\ndf = test_input\n[insert]\n'
    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)
        pd.testing.assert_frame_equal(test_env['result'], expected_result)


import numpy as np

array = np.array([
    [1, 2, 3, 1],
    [4, 5, 6, 1],
    [7, 8, 9, 2],
    [10, 11, 12, 2],
    [13, 14, 15, 3],
    [16, 17, 18, 3]
])
List = np.random.permutation(len(array))

result = ... # put solution in this variable

def g(array, List):
    return array[List]

result = g(array.copy(), List)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        array, List = data
        return array[List]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            array = np.array([
                [1, 2, 3, 1],
                [4, 5, 6, 1],
                [7, 8, 9, 2],
                [10, 11, 12, 2],
                [13, 14, 15, 3],
                [16, 17, 18, 3]
            ])
            List = np.random.permutation(len(array))
        return array, List

    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):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
array, List = 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

df = pd.DataFrame({'Col1': [1, 4, 7, 10, 13, 16],
                   'Col2': [2, 5, 8, 11, 14, 17],
                   'Col3': [3, 6, 9, 12, 15, 18],
                   'Type': [1, 1, 2, 2, 3, 3]})
List = np.random.permutation(len(df))

result = ... # put solution in this variable

def g(df, List):
    return df.iloc[List]

result = g(df.copy(), List)

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, List = data
        return df.iloc[List]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "Col1": [1, 4, 7, 10, 13, 16],
                    "Col2": [2, 5, 8, 11, 14, 17],
                    "Col3": [3, 6, 9, 12, 15, 18],
                    "Type": [1, 1, 2, 2, 3, 3],
                }
            )
            List = np.random.permutation(len(df))
        return df, List

    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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df, List = 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 g(array, List):
    array2 = array[List]
    return np.sum(array2[:, 3] != array[:, 3])

result = g(array.copy(), List)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        array, List = data
        array2 = array[List]
        return np.sum(array2[:, 3] != array[:, 3])

    def define_test_input(test_case_id):
        if test_case_id == 1:
            array = np.array([
                [1, 2, 3, 1],
                [4, 5, 6, 1],
                [7, 8, 9, 2],
                [10, 11, 12, 2],
                [13, 14, 15, 3],
                [16, 17, 18, 3]
            ])
            List = np.random.permutation(len(array))
        return array, List

    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):
    try:
        assert result == ans
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
array, List = 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 g(df, List):
    df2 = df.iloc[List].reindex().reset_index(drop=True)
    return (df2.Type != df.Type).sum()

result = g(df.copy(), List)

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, List = data
        df2 = df.iloc[List].reindex().reset_index(drop=True)
        return (df2.Type != df.Type).sum()

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "Col1": [1, 4, 7, 10, 13, 16],
                    "Col2": [2, 5, 8, 11, 14, 17],
                    "Col3": [3, 6, 9, 12, 15, 18],
                    "Type": [1, 1, 2, 2, 3, 3],
                }
            )
            List = np.random.permutation(len(df))
        return df, List

    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):
    try:
        assert result == ans
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df, List = 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)


data = np.array([['apple', 'potato', 'cheese', 'banana', 'cheese', 'banana', 'cheese', 'potato', 'egg'], ['sausage', 'banana', 'apple', 'apple', 'apple', 'sausage', 'banana', 'banana', 'banana'], ['apple', 'potato', 'sausage', 'cheese', 'cheese', 'potato', 'cheese', 'potato', 'egg']]).T

import numpy as np

data = np.array([
    ['apple', 'potato', 'cheese', 'banana', 'cheese', 'banana', 'cheese', 'potato', 'egg'],
    ['sausage', 'banana', 'apple', 'apple', 'apple', 'sausage', 'banana', 'banana', 'banana'],
    ['apple', 'potato', 'sausage', 'cheese', 'cheese', 'potato', 'cheese', 'potato', 'egg']
]).T

result = ... # put solution in this variable

def g(data):
    result = data.copy()
    for i in range(data.shape[1]):
        unique, counts = np.unique(data[:, i], return_counts=True)
        count_dict = dict(zip(unique, counts))
        for j in range(data.shape[0]):
            if count_dict[data[j, i]] < 3:
                result[j, i] = 'other'
    return result

result = g(data)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        result = data.copy()
        for i in range(data.shape[1]):
            unique, counts = np.unique(data[:, i], return_counts=True)
            count_dict = dict(zip(unique, counts))
            for j in range(data.shape[0]):
                if count_dict[data[j, i]] < 3:
                    result[j, i] = 'other'
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([
                ['apple', 'potato', 'cheese', 'banana', 'cheese', 'banana', 'cheese', 'potato', 'egg'],
                ['sausage', 'banana', 'apple', 'apple', 'apple', 'sausage', 'banana', 'banana', 'banana'],
                ['apple', 'potato', 'sausage', 'cheese', 'cheese', 'potato', 'cheese', 'potato', 'egg']
            ]).T
        if test_case_id == 2:
            data = np.array([
                ['sausage', 'banana', 'apple', 'apple', 'apple', 'sausage', 'banana', 'banana', 'banana'],
                ['apple', 'potato', 'sausage', 'cheese', 'cheese', 'potato', 'cheese', 'potato', 'egg'],
                ['apple', 'potato', 'cheese', 'banana', 'cheese', 'banana', 'cheese', 'potato', 'egg']
            ]).T
        return data

    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):
    return np.array_equal(result, ans)

exec_context = r"""
import numpy as np
data = 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)

data = DataFrame({'Qu1': ['apple', 'potato', 'cheese', 'banana', 'cheese', 'banana', 'cheese', 'potato', 'egg'], 'Qu2': ['sausage', 'banana', 'apple', 'apple', 'apple', 'sausage', 'banana', 'banana', 'banana'], 'Qu3': ['apple', 'potato', 'sausage', 'cheese', 'cheese', 'potato', 'cheese', 'potato', 'egg']})

import pandas as pd

df = pd.DataFrame({'Qu1': ['apple', 'potato', 'cheese', 'banana', 'cheese', 'banana', 'cheese', 'potato', 'egg'],
                   'Qu2': ['sausage', 'banana', 'apple', 'apple', 'apple', 'sausage', 'banana', 'banana', 'banana'],
                   'Qu3': ['apple', 'potato', 'sausage', 'cheese', 'cheese', 'potato', 'cheese', 'potato', 'egg']})

result = ... # put solution in this variable

def g(df):
    return df.where(df.apply(lambda x: x.map(x.value_counts())) >= 3, "other")

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.where(df.apply(lambda x: x.map(x.value_counts())) >= 3, "other")

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "Qu1": [
                        "apple",
                        "potato",
                        "cheese",
                        "banana",
                        "cheese",
                        "banana",
                        "cheese",
                        "potato",
                        "egg",
                    ],
                    "Qu2": [
                        "sausage",
                        "banana",
                        "apple",
                        "apple",
                        "apple",
                        "sausage",
                        "banana",
                        "banana",
                        "banana",
                    ],
                    "Qu3": [
                        "apple",
                        "potato",
                        "sausage",
                        "cheese",
                        "cheese",
                        "potato",
                        "cheese",
                        "potato",
                        "egg",
                    ],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "Qu1": [
                        "sausage",
                        "banana",
                        "apple",
                        "apple",
                        "apple",
                        "sausage",
                        "banana",
                        "banana",
                        "banana",
                    ],
                    "Qu2": [
                        "apple",
                        "potato",
                        "sausage",
                        "cheese",
                        "cheese",
                        "potato",
                        "cheese",
                        "potato",
                        "egg",
                    ],
                    "Qu3": [
                        "apple",
                        "potato",
                        "cheese",
                        "banana",
                        "cheese",
                        "banana",
                        "cheese",
                        "potato",
                        "egg",
                    ],
                }
            )
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = 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)


id    url     keep_if_dup
1     A.com   Yes
2     A.com   Yes
3     B.com   No
4     B.com   No
5     C.com   No

import numpy as np

data = np.array([
    [1, 'A.com', 'Yes'],
    [2, 'A.com', 'Yes'],
    [3, 'A.com', 'No'],
    [4, 'B.com', 'No'],
    [5, 'B.com', 'No'],
    [6, 'C.com', 'No'],
    [7, 'B.com', 'Yes']
])

result = ... # put solution in this variable

def g(data):
    unique_urls = {}
    result = []
    for row in data:
        url = row[1]
        keep_if_dup = row[2]
        if keep_if_dup == 'Yes' or url not in unique_urls:
            result.append(row)
            unique_urls[url] = True
    return np.array(result)

result = g(data.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        unique_urls = {}
        result = []
        for row in data:
            url = row[1]
            keep_if_dup = row[2]
            if keep_if_dup == 'Yes' or url not in unique_urls:
                result.append(row)
                unique_urls[url] = True
        return np.array(result)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([
                [1, 'A.com', 'Yes'],
                [2, 'A.com', 'Yes'],
                [3, 'A.com', 'No'],
                [4, 'B.com', 'No'],
                [5, 'B.com', 'No'],
                [6, 'C.com', 'No'],
                [7, 'B.com', 'Yes']
            ])
        return data

    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):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
data = 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

df = pd.DataFrame({'url': ['A.com', 'A.com', 'A.com', 'B.com', 'B.com', 'C.com', 'B.com'],
                   'keep_if_dup': ['Yes', 'Yes', 'No', 'No', 'No', 'No', 'Yes']})

result = ... # put solution in this variable

def g(df):
    return df.loc[(df['keep_if_dup'] =='Yes') | ~df['url'].duplicated()]

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.loc[(df["keep_if_dup"] == "Yes") | ~df["url"].duplicated()]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "url": [
                        "A.com",
                        "A.com",
                        "A.com",
                        "B.com",
                        "B.com",
                        "C.com",
                        "B.com",
                    ],
                    "keep_if_dup": ["Yes", "Yes", "No", "No", "No", "No", "Yes"],
                }
            )
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = 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)


id    url     drop_if_dup
1     A.com   Yes
2     A.com   Yes
3     B.com   No
4     B.com   No
5     C.com   No

import numpy as np

urls = np.array(['A.com', 'A.com', 'A.com', 'B.com', 'B.com', 'C.com', 'B.com'])
drop_if_dup = np.array(['Yes', 'Yes', 'No', 'No', 'No', 'No', 'Yes'])

result = ... # put solution in this variable

def g(urls, drop_if_dup):
    unique_urls = np.unique(urls, return_index=True)[1]
    mask = (drop_if_dup == 'No') | np.isin(np.arange(len(urls)), unique_urls)
    return urls[mask], drop_if_dup[mask]

result = g(urls.copy(), drop_if_dup.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(urls, drop_if_dup):
        unique_urls = np.unique(urls, return_index=True)[1]
        mask = (drop_if_dup == 'No') | np.isin(np.arange(len(urls)), unique_urls)
        return urls[mask], drop_if_dup[mask]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            urls = np.array(['A.com', 'A.com', 'A.com', 'B.com', 'B.com', 'C.com', 'B.com'])
            drop_if_dup = np.array(['Yes', 'Yes', 'No', 'No', 'No', 'No', 'Yes'])
        return urls, drop_if_dup

    test_input = define_test_input(test_case_id)
    expected_result = generate_ans(copy.deepcopy(test_input[0]), copy.deepcopy(test_input[1]))
    return test_input, expected_result

def exec_test(result, ans):
    try:
        assert np.array_equal(result[0], ans[0]) and np.array_equal(result[1], ans[1])
        return 1
    except:
        return 0

exec_context = r'''
import numpy as np
urls, drop_if_dup = 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

df = pd.DataFrame({'url': ['A.com', 'A.com', 'A.com', 'B.com', 'B.com', 'C.com', 'B.com'],
                   'drop_if_dup': ['Yes', 'Yes', 'No', 'No', 'No', 'No', 'Yes']})

result = ... # put solution in this variable

def g(df):
    return df.loc[(df['drop_if_dup'] =='No') | ~df['url'].duplicated()]

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.loc[(df["drop_if_dup"] == "No") | ~df["url"].duplicated()]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "url": [
                        "A.com",
                        "A.com",
                        "A.com",
                        "B.com",
                        "B.com",
                        "C.com",
                        "B.com",
                    ],
                    "drop_if_dup": ["Yes", "Yes", "No", "No", "No", "No", "Yes"],
                }
            )
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = 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 numpy as np

urls = np.array(['A.com', 'A.com', 'A.com', 'B.com', 'B.com', 'C.com', 'B.com'])
keep_if_dup = np.array(['Yes', 'Yes', 'No', 'No', 'No', 'No', 'Yes'])

result = ... # put solution in this variable

def g(urls, keep_if_dup):
    unique_urls = np.unique(urls, return_index=True)[1]
    mask = (keep_if_dup == 'Yes') | np.isin(np.arange(len(urls)), unique_urls)
    return np.column_stack((np.arange(1, len(urls) + 1)[mask], urls[mask], keep_if_dup[mask]))

result = g(urls, keep_if_dup)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(urls, keep_if_dup):
        unique_urls = np.unique(urls, return_index=True)[1]
        mask = (keep_if_dup == 'Yes') | np.isin(np.arange(len(urls)), unique_urls)
        return np.column_stack((np.arange(1, len(urls) + 1)[mask], urls[mask], keep_if_dup[mask]))

    def define_test_input(test_case_id):
        if test_case_id == 1:
            urls = np.array(['A.com', 'A.com', 'A.com', 'B.com', 'B.com', 'C.com', 'B.com'])
            keep_if_dup = np.array(['Yes', 'Yes', 'No', 'No', 'No', 'No', 'Yes'])
        return urls, keep_if_dup

    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):
    try:
        assert np.array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r'''
import numpy as np
urls, keep_if_dup = 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 g(df):
    return df.loc[(df['keep_if_dup'] =='Yes') | ~df['url'].duplicated(keep='last')]

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.loc[(df["keep_if_dup"] == "Yes") | ~df["url"].duplicated(keep="last")]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "url": [
                        "A.com",
                        "A.com",
                        "A.com",
                        "B.com",
                        "B.com",
                        "C.com",
                        "B.com",
                    ],
                    "keep_if_dup": ["Yes", "Yes", "No", "No", "No", "No", "Yes"],
                }
            )
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = 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 g(arr):
    if arr.shape[1] == 1:
        if arr.size == 1: return arr[0, 0]
        return arr.squeeze()
    unique_keys = np.unique(arr[:, 0])
    d = {k: g(arr[arr[:, 0] == k][:, 1:]) for k in unique_keys}
    return d

result = g(arr.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        if arr.shape[1] == 1:
            if arr.size == 1:
                return arr[0, 0]
            return arr.squeeze()
        unique_keys = np.unique(arr[:, 0])
        d = {k: generate_ans(arr[arr[:, 0] == k][:, 1:]) for k in unique_keys}
        return d

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                ['A', 'A1', 'A11', 1],
                ['A', 'A2', 'A12', 2],
                ['B', 'B1', 'B12', 3],
                ['C', 'C1', 'C11', 4],
                ['B', 'B2', 'B21', 5],
                ['A', 'A2', 'A21', 6]
            ])
        return arr

    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):
    try:
        assert result == ans
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
arr = 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 g(df):
    if len(df.columns) == 1:
        if df.values.size == 1: return df.values[0][0]
        return df.values.squeeze()
    grouped = df.groupby(df.columns[0])
    d = {k: g(t.iloc[:, 1:]) for k, t in grouped}
    return d

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        if len(df.columns) == 1:
            if df.values.size == 1:
                return df.values[0][0]
            return df.values.squeeze()
        grouped = df.groupby(df.columns[0])
        d = {k: generate_ans(t.iloc[:, 1:]) for k, t in grouped}
        return d

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "name": ["A", "A", "B", "C", "B", "A"],
                    "v1": ["A1", "A2", "B1", "C1", "B2", "A2"],
                    "v2": ["A11", "A12", "B12", "C11", "B21", "A21"],
                    "v3": [1, 2, 3, 4, 5, 6],
                }
            )
        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):
    try:
        assert result == ans
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = 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 numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        datetimes = data
        datetimes = datetimes.astype('datetime64[ns]')
        return datetimes

    def define_test_input(test_case_id):
        if test_case_id == 1:
            datetimes = np.array([
                '2015-12-01T00:00:00-06:00',
                '2015-12-02T00:01:00-06:00',
                '2015-12-03T00:00:00-06:00',
            ], dtype='datetime64')
        elif test_case_id == 2:
            datetimes = np.array([
                '2016-12-02T00:01:00-06:00',
                '2016-12-01T00:00:00-06:00',
                '2016-12-03T00:00:00-06:00',
            ], dtype='datetime64')
        return datetimes

    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):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

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

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):
    assert 'astype' in solution

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

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df["datetime"] = df["datetime"].dt.tz_localize(None)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "datetime": [
                        "2015-12-01 00:00:00-06:00",
                        "2015-12-02 00:01:00-06:00",
                        "2015-12-03 00:00:00-06:00",
                    ]
                }
            )
            df["datetime"] = pd.to_datetime(df["datetime"])
        elif test_case_id == 2:
            df = pd.DataFrame(
                {
                    "datetime": [
                        "2016-12-02 00:01:00-06:00",
                        "2016-12-01 00:00:00-06:00",
                        "2016-12-03 00:00:00-06:00",
                    ]
                }
            )
            df["datetime"] = pd.to_datetime(df["datetime"])
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

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)

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


import numpy as np

datetime_array = np.array(['2015-12-01T00:00:00-06:00', '2015-12-02T00:01:00-06:00', '2015-12-03T00:00:00-06:00'], dtype='datetime64')

def f(arr=datetime_array):
    # return the solution in this function
    # result = f(arr)
    ###

    arr = arr.astype('datetime64[s]')
    result = arr

    return result

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        arr = arr.astype('datetime64[s]')
        return arr

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                '2015-12-01T00:00:00-06:00',
                '2015-12-02T00:01:00-06:00',
                '2015-12-03T00:00:00-06:00',
            ], dtype='datetime64')
        elif test_case_id == 2:
            arr = np.array([
                '2016-12-02T00:01:00-06:00',
                '2016-12-01T00:00:00-06:00',
                '2016-12-03T00:00:00-06:00',
            ], dtype='datetime64')
        return arr

    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):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

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

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):
    assert 'astype' in solution

df['date'] = pd.to_datetime(['2015-12-01 00:00:00-06:00']).tz_localize('UTC').tz_convert('America/Chicago')

import pandas as pd

example_df = pd.DataFrame({'datetime': ['2015-12-01 00:00:00-06:00', '2015-12-02 00:01:00-06:00', '2015-12-03 00:00:00-06:00']})
example_df['datetime'] = pd.to_datetime(example_df['datetime'])
def f(df=example_df):
    # return the solution in this function
    # result = f(df)
    ###

    df['datetime'] = df['datetime'].dt.tz_localize(None)
    result = df

    return result

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

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df["datetime"] = df["datetime"].dt.tz_localize(None)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "datetime": [
                        "2015-12-01 00:00:00-06:00",
                        "2015-12-02 00:01:00-06:00",
                        "2015-12-03 00:00:00-06:00",
                    ]
                }
            )
            df["datetime"] = pd.to_datetime(df["datetime"])
        elif test_case_id == 2:
            df = pd.DataFrame(
                {
                    "datetime": [
                        "2016-12-02 00:01:00-06:00",
                        "2016-12-01 00:00:00-06:00",
                        "2016-12-03 00:00:00-06:00",
                    ]
                }
            )
            df["datetime"] = pd.to_datetime(df["datetime"])
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
def f(df):
[insert]
df = test_input
result = f(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)

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


import numpy as np
from datetime import datetime, timezone, timedelta

datetimes = np.array(['2015-12-01 00:00:00-06:00', '2015-12-02 00:01:00-06:00', '2015-12-03 00:00:00-06:00'], dtype='datetime64')

# Convert to timezone-aware datetime objects
# Solution goes here

def g(datetimes):
    # Remove timezone info
    datetimes = np.array([dt.replace(tzinfo=None) for dt in datetimes])
    # Sort the array
    datetimes.sort()
    return datetimes

datetimes = g(datetimes.copy())

import numpy as np
from datetime import datetime, timezone, timedelta
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        datetimes = data
        datetimes = np.array([dt.replace(tzinfo=None) for dt in datetimes])
        datetimes.sort()
        return datetimes

    def define_test_input(test_case_id):
        if test_case_id == 1:
            datetimes = np.array([
                datetime(2015, 12, 1, 0, 0, 0, tzinfo=timezone(timedelta(hours=-6))),
                datetime(2015, 12, 2, 0, 1, 0, tzinfo=timezone(timedelta(hours=-6))),
                datetime(2015, 12, 3, 0, 0, 0, tzinfo=timezone(timedelta(hours=-6))),
            ])
        elif test_case_id == 2:
            datetimes = np.array([
                datetime(2016, 12, 2, 0, 1, 0, tzinfo=timezone(timedelta(hours=-6))),
                datetime(2016, 12, 1, 0, 0, 0, tzinfo=timezone(timedelta(hours=-6))),
                datetime(2016, 12, 3, 0, 0, 0, tzinfo=timezone(timedelta(hours=-6))),
            ])
        return datetimes

    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):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
from datetime import datetime, timezone, timedelta
datetimes = test_input
[insert]
result = datetimes
"""

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):
    assert "replace" in solution

def g(df):
    df['datetime'] = df['datetime'].dt.tz_localize(None)
    df.sort_values(by='datetime', inplace=True)
    return df

df = g(df.copy())

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

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df["datetime"] = df["datetime"].dt.tz_localize(None)
        df.sort_values(by="datetime", inplace=True)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "datetime": [
                        "2015-12-01 00:00:00-06:00",
                        "2015-12-02 00:01:00-06:00",
                        "2015-12-03 00:00:00-06:00",
                    ]
                }
            )
            df["datetime"] = pd.to_datetime(df["datetime"])
        elif test_case_id == 2:
            df = pd.DataFrame(
                {
                    "datetime": [
                        "2016-12-02 00:01:00-06:00",
                        "2016-12-01 00:00:00-06:00",
                        "2016-12-03 00:00:00-06:00",
                    ]
                }
            )
            df["datetime"] = pd.to_datetime(df["datetime"])
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

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)

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


name    status    number   message
matt    active    12345    [job:  , money: none, wife: none]
james   active    23456    [group: band, wife: yes, money: 10000]
adam    inactive  34567    [job: none, money: none, wife:  , kids: one, group: jail]

import numpy as np

names = np.array(['matt', 'james', 'adam'])
statuses = np.array(['active', 'active', 'inactive'])
numbers = np.array([12345, 23456, 34567])
messages = np.array(['[job:  , money: none, wife: none]',
                     '[group: band, wife: yes, money: 10000]',
                     '[job: none, money: none, wife:  , kids: one, group: jail]'])

result = ... # put solution in this variable

import yaml

def g(names, statuses, numbers, messages):
    messages = np.char.replace(messages, '[', '{')
    messages = np.char.replace(messages, ']', '}')
    parsed_messages = np.array([yaml.safe_load(msg) for msg in messages])
    keys = ['job', 'money', 'wife', 'group', 'kids']
    expanded = np.array([[msg.get(key, 'none') for key in keys] for msg in parsed_messages])
    expanded[expanded == ''] = 'none'
    result = np.column_stack((names, statuses, numbers, expanded))
    return result

result = g(names, statuses, numbers, messages)

import numpy as np
import yaml
import copy

def generate_test_case(test_case_id):
    def generate_ans(names, statuses, numbers, messages):
        messages = np.char.replace(messages, '[', '{')
        messages = np.char.replace(messages, ']', '}')
        parsed_messages = np.array([yaml.safe_load(msg) for msg in messages])
        keys = ['job', 'money', 'wife', 'group', 'kids']
        expanded = np.array([[msg.get(key, 'none') for key in keys] for msg in parsed_messages])
        expanded[expanded == ''] = 'none'
        result = np.column_stack((names, statuses, numbers, expanded))
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            names = np.array(['matt', 'james', 'adam'])
            statuses = np.array(['active', 'active', 'inactive'])
            numbers = np.array([12345, 23456, 34567])
            messages = np.array([
                '[job:  , money: none, wife: none]',
                '[group: band, wife: yes, money: 10000]',
                '[job: none, money: none, wife:  , kids: one, group: jail]',
            ])
        if test_case_id == 2:
            names = np.array(['matt', 'james', 'adam'])
            statuses = np.array(['active', 'active', 'inactive'])
            numbers = np.array([12345, 23456, 34567])
            messages = np.array([
                '[job:  , money: 114514, wife: none, kids: one, group: jail]',
                '[group: band, wife: yes, money: 10000]',
                '[job: none, money: none, wife:  , kids: one, group: jail]',
            ])
        return names, statuses, numbers, messages

    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):
    try:
        np.testing.assert_array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
names, statuses, numbers, messages = 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

df = pd.DataFrame({'name': ['matt', 'james', 'adam'],
                   'status': ['active', 'active', 'inactive'],
                   'number': [12345, 23456, 34567],
                   'message': ['[job:  , money: none, wife: none]',
                               '[group: band, wife: yes, money: 10000]',
                               '[job: none, money: none, wife:  , kids: one, group: jail]']})

result = ... # put solution in this variable

import yaml
def g(df):
    df.message = df.message.replace(['\[','\]'],['{','}'], regex=True).apply(yaml.safe_load)
    df1 = pd.DataFrame(df.pop('message').values.tolist(), index=df.index)
    result = pd.concat([df, df1], axis=1)
    result = result.replace('', 'none')
    result = result.replace(np.nan, 'none')
    return result

result = g(df.copy())

import pandas as pd
import numpy as np
import yaml
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df.message = df.message.replace(["\[", "\]"], ["{", "}"], regex=True).apply(
            yaml.safe_load
        )
        df1 = pd.DataFrame(df.pop("message").values.tolist(), index=df.index)
        result = pd.concat([df, df1], axis=1)
        result = result.replace("", "none")
        result = result.replace(np.nan, "none")
        return result

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "name": ["matt", "james", "adam"],
                    "status": ["active", "active", "inactive"],
                    "number": [12345, 23456, 34567],
                    "message": [
                        "[job:  , money: none, wife: none]",
                        "[group: band, wife: yes, money: 10000]",
                        "[job: none, money: none, wife:  , kids: one, group: jail]",
                    ],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "name": ["matt", "james", "adam"],
                    "status": ["active", "active", "inactive"],
                    "number": [12345, 23456, 34567],
                    "message": [
                        "[job:  , money: 114514, wife: none, kids: one, group: jail]",
                        "[group: band, wife: yes, money: 10000]",
                        "[job: none, money: none, wife:  , kids: one, group: jail]",
                    ],
                }
            )
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = 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)


for product_range in products:
    mask = (product >= product_range[0]) & (product <= product_range[1])
    score[mask] *= 10

for product in products:
    df.loc[(df['product'] >= product[0]) & (df['product'] <= product[1]), 'score'] *= 10


mask = np.isin(product, products)
max_score = score[mask].max()
min_score = score[mask].min()
score[mask] = (score[mask] - min_score) / (max_score - min_score)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        product, score, prod_list = data
        mask = np.isin(product, prod_list)
        max_score = score[mask].max()
        min_score = score[mask].min()
        score[mask] = (score[mask] - min_score) / (max_score - min_score)
        return product, score

    def define_test_input(test_case_id):
        if test_case_id == 1:
            product = np.array([
                1179160,
                1066490,
                1148126,
                1069104,
                1069105,
                1160330,
                1069098,
                1077784,
                1193369,
                1179741,
            ])
            score = np.array([
                0.424654,
                0.424509,
                0.422207,
                0.420455,
                0.414603,
                0.168784,
                0.168749,
                0.168738,
                0.168703,
                0.168684,
            ])
            products = [1066490, 1077784, 1179741]
        return product, score, products

    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):
    try:
        np.testing.assert_array_equal(result[0], ans[0])
        np.testing.assert_allclose(result[1], ans[1], rtol=1e-5)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
product, score, products = test_input
[insert]
result = (product, score)
"""

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)

Max = df.loc[df['product'].isin(products), 'score'].max()
Min = df.loc[df['product'].isin(products), 'score'].min()
df.loc[df['product'].isin(products), 'score'] = (df.loc[df['product'].isin(products), 'score'] - Min) / (Max - Min)

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, prod_list = data
        Max = df.loc[df["product"].isin(prod_list), "score"].max()
        Min = df.loc[df["product"].isin(prod_list), "score"].min()
        df.loc[df["product"].isin(prod_list), "score"] = (
            df.loc[df["product"].isin(prod_list), "score"] - Min
        ) / (Max - Min)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "product": [
                        1179160,
                        1066490,
                        1148126,
                        1069104,
                        1069105,
                        1160330,
                        1069098,
                        1077784,
                        1193369,
                        1179741,
                    ],
                    "score": [
                        0.424654,
                        0.424509,
                        0.422207,
                        0.420455,
                        0.414603,
                        0.168784,
                        0.168749,
                        0.168738,
                        0.168703,
                        0.168684,
                    ],
                }
            )
            products = [1066490, 1077784, 1179741]
        return df, products

    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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df, products = 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
from datetime import datetime

dates = np.array(['2019-01-01', '2019-02-08', '2019-02-08', '2019-03-08'], dtype='datetime64')

formatted_dates = ... # put solution in this variable

formatted_dates = np.array([datetime.strptime(str(date), '%Y-%m-%d').strftime('%d-%b-%Y') for date in dates])

import numpy as np
from datetime import datetime
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        return np.array([datetime.strptime(str(date), '%Y-%m-%d').strftime('%d-%b-%Y') for date in data])

    def define_test_input(test_case_id):
        if test_case_id == 1:
            return np.array(['2019-01-01', '2019-02-08', '2019-02-08', '2019-03-08'], dtype='datetime64')

    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):
    try:
        assert np.array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r'''
import numpy as np
from datetime import datetime
dates = test_input
[insert]
result = formatted_dates
'''

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

df = pd.DataFrame({'Date':['2019-01-01','2019-02-08','2019-02-08', '2019-03-08']})
df['Date'] = pd.to_datetime(df['Date'])

df = ... # put solution in this variable

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df["Date"] = df["Date"].dt.strftime("%d-%b-%Y")
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {"Date": ["2019-01-01", "2019-02-08", "2019-02-08", "2019-03-08"]}
            )
            df["Date"] = pd.to_datetime(df["Date"])
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

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(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
from datetime import datetime

# Create an array of dates
arr = np.array(['2019-01-01', '2019-02-08', '2019-02-08', '2019-03-08'], dtype='datetime64')
List = np.array(['2019-01-17', '2019-02-20'], dtype='datetime64')

# Filter the array
arr = ... # put solution in this variable

import numpy as np
from datetime import datetime
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        arr, List = data
        arr = arr[(arr >= List[0]) & (arr <= List[1])]
        arr = np.array([datetime.strftime(date, '%d-%b-%Y %A') for date in arr.astype('O')])
        return arr

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array(['2019-01-01', '2019-02-08', '2019-02-08', '2019-03-08'], dtype='datetime64')
            List = np.array(['2019-01-17', '2019-02-20'], dtype='datetime64')
        return arr, List

    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):
    try:
        assert np.array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
from datetime import datetime
arr, List = test_input
[insert]
result = arr
"""

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)

df = df[df['Date'] >= List[0]]
df = df[df['Date'] <= List[1]]
df['Date'] = df['Date'].dt.strftime('%d-%b-%Y %A')

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data = data
        df, List = data
        df = df[df["Date"] >= List[0]]
        df = df[df["Date"] <= List[1]]
        df["Date"] = df["Date"].dt.strftime("%d-%b-%Y %A")
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {"Date": ["2019-01-01", "2019-02-08", "2019-02-08", "2019-03-08"]}
            )
            df["Date"] = pd.to_datetime(df["Date"])
            List = ["2019-01-17", "2019-02-20"]
        return df, List

    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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df,List = 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
data[:, 0] = np.roll(data[:, 0], shift=1)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data[:, 0] = np.roll(data[:, 0], shift=1)
        return data

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([
                [11.6985, 126.0],
                [43.6431, 134.0],
                [54.9089, 130.0],
                [63.1225, 126.0],
                [72.4399, 120.0],
            ])
        elif test_case_id == 2:
            data = np.array([
                [45, 126.0],
                [51, 134.0],
                [14, 130.0],
                [11, 126.0],
                [14, 120.0],
            ])
        return data

    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):
    try:
        np.testing.assert_array_almost_equal(result, ans)
        return 1
    except:
        return 0

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

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
df['#1'] = np.roll(df['#1'], shift=1)

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df["#1"] = np.roll(df["#1"], shift=1)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "#1": [11.6985, 43.6431, 54.9089, 63.1225, 72.4399],
                    "#2": [126.0, 134.0, 130.0, 126.0, 120.0],
                },
                index=[
                    "1980-01-01",
                    "1980-01-02",
                    "1980-01-03",
                    "1980-01-04",
                    "1980-01-05",
                ],
            )
        elif test_case_id == 2:
            df = pd.DataFrame(
                {"#1": [45, 51, 14, 11, 14], "#2": [126.0, 134.0, 130.0, 126.0, 120.0]},
                index=[
                    "1980-01-01",
                    "1980-01-02",
                    "1980-01-03",
                    "1980-01-04",
                    "1980-01-05",
                ],
            )
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

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
data[:, 0] = np.roll(data[:, 0], shift=-1)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data[:, 0] = np.roll(data[:, 0], shift=-1)
        return data

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([
                [11.6985, 126.0],
                [43.6431, 134.0],
                [54.9089, 130.0],
                [63.1225, 126.0],
                [72.4399, 120.0],
            ])
        elif test_case_id == 2:
            data = np.array([
                [45, 126.0],
                [51, 134.0],
                [14, 130.0],
                [11, 126.0],
                [14, 120.0],
            ])
        return data

    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):
    try:
        np.testing.assert_array_almost_equal(result, ans)
        return 1
    except:
        return 0

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

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
df['#1'] = np.roll(df['#1'], shift=-1)

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df["#1"] = np.roll(df["#1"], shift=-1)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "#1": [11.6985, 43.6431, 54.9089, 63.1225, 72.4399],
                    "#2": [126.0, 134.0, 130.0, 126.0, 120.0],
                },
                index=[
                    "1980-01-01",
                    "1980-01-02",
                    "1980-01-03",
                    "1980-01-04",
                    "1980-01-05",
                ],
            )
        elif test_case_id == 2:
            df = pd.DataFrame(
                {"#1": [45, 51, 14, 11, 14], "#2": [126.0, 134.0, 130.0, 126.0, 120.0]},
                index=[
                    "1980-01-01",
                    "1980-01-02",
                    "1980-01-03",
                    "1980-01-04",
                    "1980-01-05",
                ],
            )
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

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

data[:, 0] = np.roll(data[:, 0], shift=1)
data[:, 1] = np.roll(data[:, 1], shift=-1)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        data[:, 0] = np.roll(data[:, 0], shift=1)
        data[:, 1] = np.roll(data[:, 1], shift=-1)
        return data

    def define_test_input(test_case_id):
        if test_case_id == 1:
            data = np.array([
                [11.6985, 126.0],
                [43.6431, 134.0],
                [54.9089, 130.0],
                [63.1225, 126.0],
                [72.4399, 120.0],
            ])
        elif test_case_id == 2:
            data = np.array([
                [45, 126.0],
                [51, 134.0],
                [14, 130.0],
                [11, 126.0],
                [14, 120.0],
            ])
        return data

    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):
    try:
        np.testing.assert_array_almost_equal(result, ans)
        return 1
    except:
        return 0

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

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
df['#1'] = np.roll(df['#1'], shift=1)
df['#2'] = np.roll(df['#2'], shift=-1)

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        df["#1"] = np.roll(df["#1"], shift=1)
        df["#2"] = np.roll(df["#2"], shift=-1)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "#1": [11.6985, 43.6431, 54.9089, 63.1225, 72.4399],
                    "#2": [126.0, 134.0, 130.0, 126.0, 120.0],
                },
                index=[
                    "1980-01-01",
                    "1980-01-02",
                    "1980-01-03",
                    "1980-01-04",
                    "1980-01-05",
                ],
            )
        elif test_case_id == 2:
            df = pd.DataFrame(
                {"#1": [45, 51, 14, 11, 14], "#2": [126.0, 134.0, 130.0, 126.0, 120.0]},
                index=[
                    "1980-01-01",
                    "1980-01-02",
                    "1980-01-03",
                    "1980-01-04",
                    "1980-01-05",
                ],
            )
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

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
def g(arr):
    sh = 0
    min_R2 = np.sum((arr[:, 0] - arr[:, 1]) ** 2)
    for i in range(len(arr)):
        R2 = np.sum((arr[:, 0] - arr[:, 1]) ** 2)
        if min_R2 > R2:
            sh = i
            min_R2 = R2
        arr[:, 0] = np.roll(arr[:, 0], shift=1)
    arr[:, 0] = np.roll(arr[:, 0], shift=sh)
    return arr

arr = g(arr)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        arr = data
        sh = 0
        min_R2 = np.sum((arr[:, 0] - arr[:, 1]) ** 2)
        for i in range(len(arr)):
            R2 = np.sum((arr[:, 0] - arr[:, 1]) ** 2)
            if min_R2 > R2:
                sh = i
                min_R2 = R2
            arr[:, 0] = np.roll(arr[:, 0], shift=1)
        arr[:, 0] = np.roll(arr[:, 0], shift=sh)
        return arr

    def define_test_input(test_case_id):
        if test_case_id == 1:
            arr = np.array([
                [11.6985, 126.0],
                [43.6431, 134.0],
                [54.9089, 130.0],
                [63.1225, 126.0],
                [72.4399, 120.0],
            ])
        elif test_case_id == 2:
            arr = np.array([
                [45, 126.0],
                [51, 134.0],
                [14, 130.0],
                [11, 126.0],
                [14, 120.0],
            ])
        return arr

    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):
    try:
        np.testing.assert_array_almost_equal(result, ans)
        return 1
    except:
        return 0

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

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
def g(df):
    sh = 0
    min_R2 = 0
    for i in range(len(df)):
        min_R2 += (df['#1'].iloc[i]-df['#2'].iloc[i])**2
    for i in range(len(df)):
        R2 = 0
        for j in range(len(df)):
            R2 += (df['#1'].iloc[j] - df['#2'].iloc[j]) ** 2
        if min_R2 > R2:
            sh = i
            min_R2 = R2
        df['#1'] = np.roll(df['#1'], shift=1)
    df['#1'] = np.roll(df['#1'], shift=sh)
    return df

df = g(df)

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        sh = 0
        min_R2 = 0
        for i in range(len(df)):
            min_R2 += (df["#1"].iloc[i] - df["#2"].iloc[i]) ** 2
        for i in range(len(df)):
            R2 = 0
            for j in range(len(df)):
                R2 += (df["#1"].iloc[j] - df["#2"].iloc[j]) ** 2
            if min_R2 > R2:
                sh = i
                min_R2 = R2
            df["#1"] = np.roll(df["#1"], shift=1)
        df["#1"] = np.roll(df["#1"], shift=sh)
        return df

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "#1": [11.6985, 43.6431, 54.9089, 63.1225, 72.4399],
                    "#2": [126.0, 134.0, 130.0, 126.0, 120.0],
                },
                index=[
                    "1980-01-01",
                    "1980-01-02",
                    "1980-01-03",
                    "1980-01-04",
                    "1980-01-05",
                ],
            )
        elif test_case_id == 2:
            df = pd.DataFrame(
                {"#1": [45, 51, 14, 11, 14], "#2": [126.0, 134.0, 130.0, 126.0, 120.0]},
                index=[
                    "1980-01-01",
                    "1980-01-02",
                    "1980-01-03",
                    "1980-01-04",
                    "1980-01-05",
                ],
            )
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

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)


array = [[476, 4365, 457]]; headers = ['HeaderA', 'HeaderB', 'HeaderC']

import numpy as np

array = np.array([[476, 4365, 457]])
column_names = ['HeaderA', 'HeaderB', 'HeaderC']

array = ... # put solution in this variable

def g(array, column_names):
    return array, [name + 'X' for name in column_names]

array, column_names = g(array.copy(), column_names)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data, column_names):
        return data, [name + 'X' for name in column_names]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            array = np.array([[476, 4365, 457]])
            column_names = ['HeaderA', 'HeaderB', 'HeaderC']
        if test_case_id == 2:
            array = np.array([[114, 4365, 514]])
            column_names = ['HeaderD', 'HeaderF', 'HeaderG']
        return array, column_names

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

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result[0], ans[0])
        assert result[1] == ans[1]
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
array, column_names = test_input
[insert]
result = (array, column_names)
"""

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)

df = pd.DataFrame({'HeaderA': [476], 'HeaderB': [4365], 'HeaderC': [457]})

import pandas as pd

df = pd.DataFrame(
    {'HeaderA': [476],
     'HeaderB': [4365],
     'HeaderC': [457]})

df = ... # put solution in this variable

def g(df):
    return df.add_suffix('X')

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.add_suffix("X")

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame({"HeaderA": [476], "HeaderB": [4365], "HeaderC": [457]})
        if test_case_id == 2:
            df = pd.DataFrame({"HeaderD": [114], "HeaderF": [4365], "HeaderG": [514]})
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

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)


array = [[476, 4365, 457]], headers = ['HeaderA', 'HeaderB', 'HeaderC']

import numpy as np

array = np.array([[476, 4365, 457]])
headers = ['HeaderA', 'HeaderB', 'HeaderC']

array = ... # put solution in this variable

def g(array, headers):
    return array, ['X' + header for header in headers]

array, headers = g(array.copy(), headers)

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data, headers):
        return data, ['X' + header for header in headers]

    def define_test_input(test_case_id):
        if test_case_id == 1:
            array = np.array([[476, 4365, 457]])
            headers = ['HeaderA', 'HeaderB', 'HeaderC']
        if test_case_id == 2:
            array = np.array([[114, 4365, 514]])
            headers = ['HeaderD', 'HeaderF', 'HeaderG']
        return array, headers

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

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result[0], ans[0])
        assert result[1] == ans[1]
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
array, headers = test_input
[insert]
result = (array, headers)
"""

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 g(df):
    return df.add_prefix('X')

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.add_prefix("X")

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame({"HeaderA": [476], "HeaderB": [4365], "HeaderC": [457]})
        if test_case_id == 2:
            df = pd.DataFrame({"HeaderD": [114], "HeaderF": [4365], "HeaderG": [514]})
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

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

array = np.array([[476, 4365, 457, 345]])
headers = ['HeaderA', 'HeaderB', 'HeaderC', 'HeaderX']
array, headers = ... # put solution in these variables

def g(array, headers):
    new_headers = []
    for col in headers:
        if not col.endswith('X'):
            new_headers.append(col + 'X')
        else:
            new_headers.append(col)
    new_headers = ['X' + col for col in new_headers]
    return array, new_headers

array, headers = g(array.copy(), headers.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data, headers):
        new_headers = []
        for col in headers:
            if not col.endswith('X'):
                new_headers.append(col + 'X')
            else:
                new_headers.append(col)
        new_headers = ['X' + col for col in new_headers]
        return data, new_headers

    def define_test_input(test_case_id):
        if test_case_id == 1:
            array = np.array([[476, 4365, 457, 345]])
            headers = ['HeaderA', 'HeaderB', 'HeaderC', 'HeaderX']
        if test_case_id == 2:
            array = np.array([[114, 4365, 514, 345]])
            headers = ['HeaderD', 'HeaderF', 'HeaderG', 'HeaderX']
        return array, headers

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

def exec_test(result, ans):
    try:
        np.testing.assert_array_equal(result[0], ans[0])
        assert result[1] == ans[1]
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
array, headers = test_input
[insert]
result = (array, headers)
"""

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

df = pd.DataFrame(
    {'HeaderA': [476],
     'HeaderB': [4365],
     'HeaderC': [457],
     "HeaderX": [345]})

df = ... # put solution in this variable

def g(df):
    for col in df.columns:
        if not col.endswith('X'):
            df.rename(columns={col: col+'X'}, inplace=True)
    return df.add_prefix('X')

df = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        for col in df.columns:
            if not col.endswith("X"):
                df.rename(columns={col: col + "X"}, inplace=True)
        return df.add_prefix("X")

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "HeaderA": [476],
                    "HeaderB": [4365],
                    "HeaderC": [457],
                    "HeaderX": [345],
                }
            )
        if test_case_id == 2:
            df = pd.DataFrame(
                {
                    "HeaderD": [114],
                    "HeaderF": [4365],
                    "HeaderG": [514],
                    "HeaderX": [345],
                }
            )
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

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)


def g(data):
    unique_groups = np.unique(data['group'])
    result = []
    for group in unique_groups:
        group_data = data[data['group'] == group]
        group_color = group_data['group_color'][0]
        means = [group_data[name].mean() for name in data.dtype.names if name.startswith('val')]
        result.append((group, group_color, *means))
    dtype = [('group', 'U1'), ('group_color', 'U5')] + [(name, 'f4') for name in data.dtype.names if name.startswith('val')]
    return np.array(result, dtype=dtype)

result = g(data.copy())

import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        unique_groups = np.unique(data['group'])
        result = []
        for group in unique_groups:
            group_data = data[data['group'] == group]
            group_color = group_data['group_color'][0]
            means = [group_data[name].mean() for name in data.dtype.names if name.startswith('val')]
            result.append((group, group_color, *means))
        dtype = [('group', 'U1'), ('group_color', 'U5')] + [(name, 'f4') for name in data.dtype.names if name.startswith('val')]
        return np.array(result, dtype=dtype)

    def define_test_input(test_case_id):
        if test_case_id == 1:
            dtype = [('group', 'U1'), ('group_color', 'U5'), ('val1', 'i4'), ('val2', 'i4'), ('val3', 'i4')]
            data = np.array([
                ('A', 'green', 5, 4, 1),
                ('A', 'green', 2, 2, 1),
                ('A', 'green', 3, 8, 4),
                ('B', 'blue', 4, 5, 5),
                ('B', 'blue', 5, 7, 1)
            ], dtype=dtype)
        return data

    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):
    try:
        assert np.array_equal(result, ans)
        return 1
    except:
        return 0

exec_context = r"""
import numpy as np
data = 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

df = pd.DataFrame({ 'group': ['A', 'A', 'A', 'B', 'B'], 'group_color' : ['green', 'green', 'green', 'blue', 'blue'], 'val1': [5, 2, 3, 4, 5], 'val2' : [4, 2, 8, 5, 7],'val3':[1,1,4,5,1] })

result = ... # put solution in this variable

def g(df):
    return df.groupby('group').agg(lambda x : x.head(1) if x.dtype=='object' else x.mean())

result = g(df.copy())

import pandas as pd
import numpy as np
import copy

def generate_test_case(test_case_id):
    def generate_ans(data):
        df = data
        return df.groupby("group").agg(
            lambda x: x.head(1) if x.dtype == "object" else x.mean()
        )

    def define_test_input(test_case_id):
        if test_case_id == 1:
            df = pd.DataFrame(
                {
                    "group": ["A", "A", "A", "B", "B"],
                    "group_color": ["green", "green", "green", "blue", "blue"],
                    "val1": [5, 2, 3, 4, 5],
                    "val2": [4, 2, 8, 5, 7],
                    "val3": [1, 1, 4, 5, 1],
                }
            )
        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):
    try:
        pd.testing.assert_frame_equal(result, ans, check_dtype=False)
        return 1
    except:
        return 0

exec_context = r"""
import pandas as pd
import numpy as np
df = 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)