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

Code before:
        pct_change = PercentChange(
            inputs=[EquityPricing.close, ],
            window_length=window_length,
        )

        today = datetime64(1, 'ns')
        assets = arange(8)

        seed(seed_value)  # Seed so we get deterministic results.
        test_data = randn(window_length, 8)
        test_data[0] = array([1, 2, 2, 1, -1, -1, 0, nan])
        test_data[-1] = array([2, 1, 2, -2, 2, -2, 1, 1])

        # Calculate the expected percent change
        expected = array([1, -0.5, 0, -3, 3, -1, inf, nan])

        out = empty((8,), dtype=float)
        pct_change.compute(today, assets, out, test_data)

        check_allclose(expected, out)

        with self.assertRaises(ValueError):
            PercentChange(inputs=(), window_length=2)

        with self.assertRaises(ValueError):
            PercentChange(inputs=[EquityPricing.close, ], window_length=1)

    def gen_ranking_cases():
        seeds = range(int(1e4), int(1e5), int(1e4))
        methods = ('ordinal', 'average')
        use_mask_values = (True, False)
        set_missing_values = (True, False)
        ascending_values = (True, False)
        return product(
            seeds,
            methods,
            use_mask_values,
            set_missing_values,
            ascending_values,
        )

    @parameterized.expand(gen_ranking_cases())
    def test_masked_rankdata_2d(self,
                                seed_value,
                                method,
                                use_mask,
                                set_missing,
                                ascending):
        eyemask = ~eye(5, dtype=bool)
        nomask = ones((5, 5), dtype=bool)


Review comment (suggestion):
```suggestion
            PercentChange(inputs=[EquityPricing.close], window_length=1)
```

Common style generally doesn't use trailing commas at the end of a sequence if there's a close-brace on the same line.

The main reason for preferring something like:

```python
[
   foo,
   bar,
]
```

over 

```python
[
   foo,
   bar
]
```

is that the former style minimizes the required diff for adding a new line to the end of the list (or function call / dict, etc.), because you can just add the new line, but don't need to add the trailing comma to the previous line

Code after:
        pct_change = PercentChange(
            inputs=[EquityPricing.close, ],
            window_length=window_length,
        )

        today = datetime64(1, 'ns')
        assets = arange(8)

        seed(seed_value)  # Seed so we get deterministic results.
        middle_rows = randn(window_length - 2, 8)
        first_row = array([1, 2, 2, 1, -1, -1, 0, nan])
        end_row = array([2, 1, 2, -2, 2, -2, 1, 1])
        test_data = np.vstack([first_row, middle_rows, end_row])

        # Calculate the expected percent change
        expected = array([1, -0.5, 0, -3, 3, -1, inf, nan])

        out = empty((8,), dtype=float)
        pct_change.compute(today, assets, out, test_data)

        check_allclose(expected, out)

        with self.assertRaises(ValueError):
            PercentChange(inputs=(), window_length=2)

        with self.assertRaises(ValueError):
            PercentChange(inputs=[EquityPricing.close], window_length=1)

    def gen_ranking_cases():
        seeds = range(int(1e4), int(1e5), int(1e4))
        methods = ('ordinal', 'average')
        use_mask_values = (True, False)
        set_missing_values = (True, False)
        ascending_values = (True, False)
        return product(
            seeds,
            methods,
            use_mask_values,
            set_missing_values,
            ascending_values,
        )

    @parameterized.expand(gen_ranking_cases())
    def test_masked_rankdata_2d(self,
                                seed_value,
                                method,
                                use_mask,
                                set_missing,
                                ascending):
        eyemask = ~eye(5, dtype=bool)
        nomask = ones((5, 5), dtype=bool)