TST: make test_astype_categorical_to_other deterministic
State: closed

The use of an unseeded random number generator means that this test can
occasionally fail for no particular reason.

In particular, I saw the following error:
```
=================================== FAILURES ===================================
______________ TestSeriesDtypes.test_astype_categorical_to_other _______________

self = <pandas.tests.series.test_dtypes.TestSeriesDtypes object at 0x7f223951b750>

    def test_astype_categorical_to_other(self):

        df = DataFrame({'value': np.random.randint(0, 10000, 100)})
        labels = ["{0} - {1}".format(i, i + 499) for i in range(0, 10000, 500)]
        cat_labels = Categorical(labels, labels)

        df = df.sort_values(by=['value'], ascending=True)
        df['value_group'] = pd.cut(df.value, range(0, 10500, 500),
                                   right=False, labels=cat_labels)

        s = df['value_group']
        expected = s
        tm.assert_series_equal(s.astype('category'), expected)
        tm.assert_series_equal(s.astype(CategoricalDtype()), expected)
        msg = (r"could not convert string to float: '(0 - 499|9500 - 9999)'|"
               r"invalid literal for float\(\): (0 - 499|9500 - 9999)")
        with pytest.raises(ValueError, match=msg):
>           s.astype('float64')
E           AssertionError: Pattern 'could not convert string to float: '(0 - 499|9500 - 9999)'|invalid literal for float\(\): (0 - 499|9500 - 9999)' not found in 'invalid literal for float(): 9000 - 9499'
```
By setting the random number seed, this should no longer be able to happen.

- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`


Labels:
name: Testing
description: pandas testing functions or related to the test suite

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26244?src=pr&el=h1) Report
> Merging [#26244](https://codecov.io/gh/pandas-dev/pandas/pull/26244?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9feb3ad92cc0397a04b665803a49299ee7aa1037?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/26244/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/26244?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #26244      +/-   ##
==========================================
- Coverage   91.97%   91.96%   -0.01%     
==========================================
  Files         175      175              
  Lines       52368    52368              
==========================================
- Hits        48164    48160       -4     
- Misses       4204     4208       +4
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.52% <ø> (ø)` | :arrow_up: |
| #single | `40.69% <ø> (-0.15%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26244?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26244/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26244/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.9% <0%> (-0.12%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26244?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/26244?src=pr&el=footer). Last update [9feb3ad...a93b15e](https://codecov.io/gh/pandas-dev/pandas/pull/26244?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/26244?src=pr&el=h1) Report
> Merging [#26244](https://codecov.io/gh/pandas-dev/pandas/pull/26244?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/9feb3ad92cc0397a04b665803a49299ee7aa1037?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/26244/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/26244?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #26244      +/-   ##
==========================================
- Coverage   91.97%   91.96%   -0.01%     
==========================================
  Files         175      175              
  Lines       52368    52368              
==========================================
- Hits        48164    48160       -4     
- Misses       4204     4208       +4
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.52% <ø> (ø)` | :arrow_up: |
| #single | `40.69% <ø> (-0.15%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26244?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26244/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26244/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.9% <0%> (-0.12%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26244?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/26244?src=pr&el=footer). Last update [9feb3ad...a93b15e](https://codecov.io/gh/pandas-dev/pandas/pull/26244?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Hmm the message on your traceback doesn't match the current test. Were you getting this on master? 
Nope, we're still running pandas 0.24.1.

But it may be worth making this test deterministic regardless....
Yea not opposed to that. Do you see an easy way to get rid of the random call altogether though? On initial glance may be easier to read if we were to use literal values with a smaller frame if it's not too much extra effort
I'm sure literal values with a smaller frame would be even better, but I
don't have the time to dive into the details of this test.

On Mon, Apr 29, 2019 at 6:14 PM William Ayd <notifications@github.com>
wrote:

> Yea not opposed to that. Do you see an easy way to get rid of the random
> call altogether though? On initial glance may be easier to read if we were
> to use literal values with a smaller frame if it's not too much extra effort
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/pandas-dev/pandas/pull/26244#issuecomment-487795222>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAJJFVUDPNMQ6YTLDHB27CTPS6MOLANCNFSM4HJHTCEQ>
> .
>

fixed on master, xref #25225
thanks @shoyer