pytest-regressions icon indicating copy to clipboard operation
pytest-regressions copied to clipboard

Pytest data regression does not recognize float64 as valid object

Open gghiguchi opened this issue 5 years ago • 4 comments

Got this error when using a data regression on top os a numpy created array of zeros, that creates the array as float64 by default

gghiguchi avatar Feb 03 '20 16:02 gghiguchi

Can you please provide a code sample that reproduces the error? Or, if not, the stacktrace with the full error message.

Thanks!

tadeu avatar Feb 10 '20 22:02 tadeu

Sure

    def test_regression(data_regression):
        from numpy import float64
    
        float_64_numpy_object = float64(10)
>       data_regression.check(float_64_numpy_object)

test_create_scas_calc_dict.py:122: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/home/gghiguchi/Work/miniconda/envs/rfdap/lib/python3.6/site-packages/pytest_regressions/data_regression.py:55: in dump
    encoding="utf-8",
/home/gghiguchi/Work/miniconda/envs/rfdap/lib/python3.6/site-packages/yaml/__init__.py:278: in dump_all
    dumper.represent(data)
/home/gghiguchi/Work/miniconda/envs/rfdap/lib/python3.6/site-packages/yaml/representer.py:27: in represent
    node = self.represent_data(data)
/home/gghiguchi/Work/miniconda/envs/rfdap/lib/python3.6/site-packages/yaml/representer.py:58: in represent_data
    node = self.yaml_representers[None](self, data)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pytest_regressions.data_regression.RegressionYamlDumper object at 0x7f85fe360b38>, data = 10.0

    def represent_undefined(self, data):
>       raise RepresenterError("cannot represent an object", data)
E       yaml.representer.RepresenterError: ('cannot represent an object', 10.0)

/home/gghiguchi/Work/miniconda/envs/rfdap/lib/python3.6/site-packages/yaml/representer.py:231: RepresenterError

gghiguchi avatar Feb 17 '20 18:02 gghiguchi

Perhaps this can be solved by using the new NDArraysRegressionFixture? @tovrstra What do you think?

tarcisiofischer avatar Sep 15 '21 01:09 tarcisiofischer

That would indeed be a solution. The code was recently merged in the master branch (#72) and there is still some API discussion (#73). I believe both num_regressions and ndarrays_regression should work. Just keep in mind that these expect a dictionionary with strings as keys and arrays as values. If you plan to use other shapes than 1D arrays, ndarrays_regression would be the best fit.

tovrstra avatar Sep 15 '21 06:09 tovrstra