Repository: quantopian/zipline
File: tests/pipeline/test_adjusted_array.py (Python)

Code before:
        expected_data = array([
            ['aaa-foo', 'bbb-foo', 'ccc-foo'],
            ['ddd-foo', 'eee-foo', 'fff-foo'],
            ['ggg-foo', 'hhh-foo', 'iii-foo'],
            ['jjj-foo', 'kkk-foo', 'lll-foo'],
            ['mmm-foo', 'nnn-foo', 'ooo-foo'],
        ])
        expected_label_array = LabelArray(expected_data, missing_value='')

        expected_adj_array = AdjustedArray(
            data=expected_label_array,
            adjustments={4: [ObjectOverwrite(2, 3, 0, 0, 'ppp-foo')]},
            missing_value='',
        )

        adj_array.update_labels(lambda x: x + '-foo')

        # Check that the mapped AdjustedArray has the expected baseline
        # values and adjustment values.
        check_arrays(adj_array.data, expected_adj_array.data)
        self.assertEqual(adj_array.adjustments, expected_adj_array.adjustments)

    @parameterized.expand([(
        # Initial adjustments
        {
            1: [Float64Multiply(0, 4, 1, 1, 0.5),
                Float64Overwrite(3, 3, 4, 4, 4.2)],
            2: [Float64Multiply(0, 2, 0, 0, 0.14)],
            4: [Float64Overwrite(0, 3, 0, 0, 4.0)],
        },

        # Adjustments to add
        {
            1: [Float64Overwrite(0, 0, 1, 1, 3.7)],
            2: [Float64Multiply(0, 4, 3, 3, 10.0),
                Float64Overwrite(5, 5, 4, 4, 1.7)],
            3: [Float64Multiply(0, 4, 2, 2, 0.99),
                Float64Multiply(0, 1, 4, 4, 5.06)],
        },

        # Expected adjustments with 'append'
        {
            1: [Float64Multiply(0, 4, 1, 1, 0.5),
                Float64Overwrite(3, 3, 4, 4, 4.2),
                Float64Overwrite(0, 0, 1, 1, 3.7)],
            2: [Float64Multiply(0, 2, 0, 0, 0.14),
                Float64Multiply(0, 4, 3, 3, 10.0),
                Float64Overwrite(5, 5, 4, 4, 1.7)],
            3: [Float64Multiply(0, 4, 2, 2, 0.99),
                Float64Multiply(0, 1, 4, 4, 5.06)],
            4: [Float64Overwrite(0, 3, 0, 0, 4.0)],

Review comment (suggestion):
One thing that might help clarify this further would be to bind these adjustments to variables, e.g.:

```
A = Float64Multiply(...)
B = Float64Overwrite(...)
```

Then your parameterized setup would look like:

```
# Initial
{1 : [A, B], 2: [C], 3: [D]},
# To add
{1: [E], 2: [F, G], 3: [H]},
# Expected with append.
...
# Expected with prepend.
```

The reason this might help is that the values in the adjustments themselves aren't really all that important here. What we care is just that, whatever the values in the adjustments, they get rearranged in the right way after merging.

Code after:
        expected_data = array([
            ['aaa-foo', 'bbb-foo', 'ccc-foo'],
            ['ddd-foo', 'eee-foo', 'fff-foo'],
            ['ggg-foo', 'hhh-foo', 'iii-foo'],
            ['jjj-foo', 'kkk-foo', 'lll-foo'],
            ['mmm-foo', 'nnn-foo', 'ooo-foo'],
        ])
        expected_label_array = LabelArray(expected_data, missing_value='')

        expected_adj_array = AdjustedArray(
            data=expected_label_array,
            adjustments={4: [ObjectOverwrite(2, 3, 0, 0, 'ppp-foo')]},
            missing_value='',
        )

        adj_array.update_labels(lambda x: x + '-foo')

        # Check that the mapped AdjustedArray has the expected baseline
        # values and adjustment values.
        check_arrays(adj_array.data, expected_adj_array.data)
        self.assertEqual(adj_array.adjustments, expected_adj_array.adjustments)

    A = Float64Multiply(0, 4, 1, 1, 0.5)
    B = Float64Overwrite(3, 3, 4, 4, 4.2)
    C = Float64Multiply(0, 2, 0, 0, 0.14)
    D = Float64Overwrite(0, 3, 0, 0, 4.0)
    E = Float64Overwrite(0, 0, 1, 1, 3.7)
    F = Float64Multiply(0, 4, 3, 3, 10.0)
    G = Float64Overwrite(5, 5, 4, 4, 1.7)
    H = Float64Multiply(0, 4, 2, 2, 0.99)
    S = Float64Multiply(0, 1, 4, 4, 5.06)

    @parameterized.expand([(
        # Initial adjustments
        {
            1: [A, B],
            2: [C],
            4: [D],
        },

        # Adjustments to add
        {
            1: [E],
            2: [F, G],
            3: [H, S],
        },

        # Expected adjustments with 'append'
        {
            1: [A, B, E],
            2: [C, F, G],