STY: use pytest.raises context manager (plotting, reductions, scalar...)
State: closed

xref #24332


Labels:
name: CI
description: Continuous Integration
name: Code Style
description: Code style, linting, code_checks

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25483?src=pr&el=h1) Report
> Merging [#25483](https://codecov.io/gh/pandas-dev/pandas/pull/25483?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/ae1ab8993c5152ee14a1c4bb3577d268fb3b90e3?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/25483/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/25483?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #25483      +/-   ##
==========================================
- Coverage   91.75%   91.75%   -0.01%     
==========================================
  Files         173      173              
  Lines       52953    52953              
==========================================
- Hits        48587    48586       -1     
- Misses       4366     4367       +1
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.31% <ø> (ø)` | :arrow_up: |
| #single | `41.72% <ø> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25483?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/25483/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `87.57% <0%> (-0.1%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25483?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25483?src=pr&el=footer). Last update [ae1ab89...3b80987](https://codecov.io/gh/pandas-dev/pandas/pull/25483?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25483?src=pr&el=h1) Report
> Merging [#25483](https://codecov.io/gh/pandas-dev/pandas/pull/25483?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/ae1ab8993c5152ee14a1c4bb3577d268fb3b90e3?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/25483/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/25483?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master   #25483   +/-   ##
=======================================
  Coverage   91.75%   91.75%           
=======================================
  Files         173      173           
  Lines       52953    52953           
=======================================
  Hits        48587    48587           
  Misses       4366     4366
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.31% <ø> (ø)` | :arrow_up: |
| #single | `41.71% <ø> (ø)` | :arrow_up: |


------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25483?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25483?src=pr&el=footer). Last update [ae1ab89...3b80987](https://codecov.io/gh/pandas-dev/pandas/pull/25483?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

thanks @simonjayhawkins keep em coming!
@simonjayhawkins this last one is still failing on our wheel builder (may not be this exact PR): https://travis-ci.org/MacPython/pandas-wheels/jobs/501317594

can you do a PR to fix.

```
=================================== FAILURES ===================================
_________________________ TestSafeSort.test_unsortable _________________________
[gw1] linux -- Python 3.6.6 /venv/bin/python
self = <pandas.tests.test_sorting.TestSafeSort object at 0x7f245d73c278>
    @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails")
    def test_unsortable(self):
        # GH 13714
        arr = np.array([1, 2, datetime.now(), 0, 3], dtype=object)
        msg = (r"'(<|>)' not supported between instances of"
               r" 'datetime\.datetime' and 'int'|"
               r"unorderable types: int\(\) > datetime\.datetime\(\)")
        if compat.PY2:
            # RuntimeWarning: tp_compare didn't return -1 or -2 for exception
            with warnings.catch_warnings():
                with pytest.raises(TypeError, match=msg):
                    safe_sort(arr)
        else:
            with pytest.raises(TypeError, match=msg):
>               safe_sort(arr)
E               AssertionError: Pattern ''(<|>)' not supported between instances of 'datetime\.datetime' and 'int'|unorderable types: int\(\) > datetime\.datetime\(\)' not found in ''>' not supported between instances of 'int' and 'datetime.datetime''
/venv/lib/python3.6/site-packages/pandas/tests/test_sorting.py:422: AssertionError
=============================== warnings summary ===============================
/venv/lib/python3.6/site-packages/_pytest/assertion/rewrite.py:268: PytestWarning: Module already imp
```