Skip to content

Fixtures making IntNA tests difficult to run interactively #24326

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

Closed
jbrockmendel opened this issue Dec 17, 2018 · 3 comments
Closed

Fixtures making IntNA tests difficult to run interactively #24326

jbrockmendel opened this issue Dec 17, 2018 · 3 comments
Labels
Error Reporting Incorrect or improved errors from pandas

Comments

@jbrockmendel
Copy link
Member

Trying to run tests.arrays.test_integer TestArithmeticOps.test_error in the REPL, need to produce the data arg that gets passed to test_error. data is defined in a fixture:

@pytest.fixture(params=[Int8Dtype, Int16Dtype, Int32Dtype, Int64Dtype,
                        UInt8Dtype, UInt16Dtype, UInt32Dtype, UInt64Dtype])
def dtype(request):
    return request.param()


@pytest.fixture
def data(dtype):
    return integer_array(make_data(), dtype=dtype)

Trying to do this manually:

>>> from pandas.tests.arrays.test_integer import *
>>> dtype = Int64Dtype
>>>
>>> d = make_data()
>>> dat = integer_array(d, dtype=dtype)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pandas/core/arrays/integer.py", line 104, in integer_array
    values, mask = coerce_to_array(values, dtype=dtype, copy=copy)
  File "pandas/core/arrays/integer.py", line 159, in coerce_to_array
    raise ValueError("invalid dtype specified {}".format(dtype))
ValueError: invalid dtype specified <class 'pandas.core.arrays.integer.Int64Dtype'>

What am I missing here? Figuring out exactly what is tested should be really easy.

@TomAugspurger
Copy link
Contributor

You need to call the dtype.

dat = integer_array(d, dtype=dtype())

I think having an actual repr for instances of that dtype may help. with the confusion. We could also check in coerce_to_array whether the dtype is a class, rather than an instance.

@TomAugspurger TomAugspurger added Usability Error Reporting Incorrect or improved errors from pandas labels Dec 18, 2018
@jbrockmendel
Copy link
Member Author

thanks

@TomAugspurger
Copy link
Contributor

Might leave this open to see how things can be improved.

I think part of the confusion is that NumPy's top-level np.<dtype> functions / classes are kinda weird. You're expected to pass the class in places where we expect the dtypes.

pd.Series([1, 2], dtype=np.int32)

rather than np.int32() which returns... something.

pyarrow's pa.array() expects instances of its top-level types, rather than the class, so we're consistent with pyarrow here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

No branches or pull requests

2 participants