Skip to content

TST: Fixed failures in JSON asserts #20827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 26, 2018

Conversation

TomAugspurger
Copy link
Contributor

Fixes an occasional failure in the json tests. They'd fail when the
Series held objects of equal length.

pandas/tests/extension/json/test_json.py:114:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pandas/util/testing.py:1224: in assert_series_equal
    _testing.assert_almost_equal(left.get_values(), right.get_values(),
pandas/core/series.py:466: in get_values
    return self._data.get_values()
pandas/core/internals.py:4742: in get_values
    return np.array(self._block.to_dense(), copy=False)
pandas/core/internals.py:1940: in to_dense
    return np.asarray(self.values)
../../Envs/pandas-dev/lib/python3.6/site-packages/numpy/numpy/core/numeric.py:500: in asarray
    return array(a, dtype, copy=False, order=order)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = {'a': 1}, key = 0

    def __getitem__(self, key):
        if key in self.data:
            return self.data[key]
        if hasattr(self.__class__, "__missing__"):
            return self.__class__.__missing__(self, key)
>       raise KeyError(key)
E       KeyError: 0

Work around that by converting to dicts before comparing.

Fixes an occasional failure in the json tests. They'd fail when the
Series held objects of equal length.

```pytb
pandas/tests/extension/json/test_json.py:114:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
pandas/util/testing.py:1224: in assert_series_equal
    _testing.assert_almost_equal(left.get_values(), right.get_values(),
pandas/core/series.py:466: in get_values
    return self._data.get_values()
pandas/core/internals.py:4742: in get_values
    return np.array(self._block.to_dense(), copy=False)
pandas/core/internals.py:1940: in to_dense
    return np.asarray(self.values)
../../Envs/pandas-dev/lib/python3.6/site-packages/numpy/numpy/core/numeric.py:500: in asarray
    return array(a, dtype, copy=False, order=order)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = {'a': 1}, key = 0

    def __getitem__(self, key):
        if key in self.data:
            return self.data[key]
        if hasattr(self.__class__, "__missing__"):
            return self.__class__.__missing__(self, key)
>       raise KeyError(key)
E       KeyError: 0
```

Work around that by converting to dicts before comparing.
@TomAugspurger TomAugspurger added the ExtensionArray Extending pandas with custom dtypes or arrays. label Apr 26, 2018
@TomAugspurger TomAugspurger added this to the 0.23.0 milestone Apr 26, 2018
@codecov
Copy link

codecov bot commented Apr 26, 2018

Codecov Report

Merging #20827 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #20827   +/-   ##
=======================================
  Coverage   91.77%   91.77%           
=======================================
  Files         153      153           
  Lines       49281    49281           
=======================================
  Hits        45230    45230           
  Misses       4051     4051
Flag Coverage Δ
#multiple 90.17% <ø> (ø) ⬆️
#single 41.88% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 630ef16...e774eec. Read the comment docs.

@TomAugspurger
Copy link
Contributor Author

Apologies for the quick self-merge, but I'm going to merge this on green so that #20814 can be re-run on top if it. This is test-only so I think things are OK.

@TomAugspurger TomAugspurger merged commit e9190bf into pandas-dev:master Apr 26, 2018
@TomAugspurger TomAugspurger deleted the json-assert branch April 26, 2018 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant