BUG: upcasting on reshaping ops #13247 by jaehoonhwang · Pull Request #15594 · pandas-dev/pandas (original) (raw)

I could be misreading this, but I don't think you need the for loop over klass anymore. pytest will handle that for you, since you're doing the parametrize.
I think this will also fail, since this class eventually inherits from TestCase, which doesn't play well with parametrized fixtures. I'd try it like this:

import numpy as np from pandas import Series, DataFrame, Panel import pandas as pd import pytest

class TestConcatUpcast(object):

@pytest.mark.parametrize('pdt', [Series, DataFrame, Panel])
def test_concat_no_unnecessary_upcats_pytest(self, pdt):
    # GH 13247
    dims = pdt().ndim
    for dt in np.sctypes['float']:
        dfs = [pdt(np.array([1], dtype=dt, ndmin=dims)),
               pdt(np.array([np.nan], dtype=dt, ndmin=dims)),
               pdt(np.array([5], dtype=dt, ndmin=dims))]
        x = pd.concat(dfs)
        assert x.values.dtype == dt

        objs = []
        objs.append(pdt(np.array([1], dtype=np.float32, ndmin=dims)))
        objs.append(pdt(np.array([1], dtype=np.float16, ndmin=dims)))
        assert pd.concat(objs).values.dtype == np.float32

        objs = []
        objs.append(pdt(np.array([1], dtype=np.int32, ndmin=dims)))
        objs.append(pdt(np.array([1], dtype=np.int64, ndmin=dims)))
        assert pd.concat(objs).values.dtype == np.int64

        objs = []
        objs.append(pdt(np.array([1], dtype=np.int32, ndmin=dims)))
        objs.append(pdt(np.array([1], dtype=np.float16, ndmin=dims)))
        assert pd.concat(objs).values.dtype == np.float64

This doesn't parametrize all that well over the dtype argument, so probably best to just leave it there.

If you want to leave comments on #15608, would appreciate your insight.