Skip to content

BUG: ExtensionArray test_unstack assumes missing values are nan #36986

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
3 tasks done
jrm5100 opened this issue Oct 8, 2020 · 0 comments · Fixed by #36987
Closed
3 tasks done

BUG: ExtensionArray test_unstack assumes missing values are nan #36986

jrm5100 opened this issue Oct 8, 2020 · 0 comments · Fixed by #36987
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays. Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@jrm5100
Copy link
Contributor

jrm5100 commented Oct 8, 2020

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

Running pytest with this fixture:

import random

import pytest
from pandas_genomics import GenotypeDtype, GenotypeArray, Variant

random.seed(1855)

@pytest.fixture
def data():
    """Length-100 array for this type.
    * data[0] and data[1] should both be non missing
    * data[0] and data[1] should not be equal
    """
    alleles = ['A', 'T', 'G']
    variant = Variant(variant_id='rs12345', chromosome='chr1', coordinate=123456, alleles=alleles)
    genotypes = [variant.make_genotype('A', 'T'), variant.make_genotype('T', 'T')]
    for i in range(98):
        genotypes.append(variant.make_genotype(random.choice(alleles), random.choice(alleles)))
    return GenotypeArray(values=genotypes)

class TestReshaping(base.BaseReshapingTests):
    pass

Problem description

I'm working on an ExtensionArray as part of a package called pandas-genomics.
I've almost got all of the ExtensionArray tests passing. It isn't possible to pass test_unstack without altering the test itself. For example, the series-index1 test case fails this assertion:

expected = ser.astype(object).unstack(level=level)
result = result.astype(object)

self.assert_frame_equal(result, expected)

In this case, result is

     A          B
a  A/T  <Missing>
b  T/T        T/T

and expected is

     A    B
a  A/T  NaN
b  T/T  T/T

<Missing> is the na_value for my ExtensionDtype.

I've confirmed that this is resolved by using fill_value to supply the na_value

expected = ser.astype(object).unstack(level=level, fill_value=data.dtype.na_value)

Expected Output

Test passes

Output of pd.show_versions()

INSTALLED VERSIONS

commit : db08276
python : 3.7.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 1.1.3
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 19.2.3
setuptools : 41.2.0
Cython : None
pytest : 5.4.3
hypothesis : None
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.18.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@jrm5100 jrm5100 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 8, 2020
@jrm5100 jrm5100 mentioned this issue Oct 8, 2020
5 tasks
@jreback jreback added ExtensionArray Extending pandas with custom dtypes or arrays. Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 8, 2020
@jreback jreback added this to the 1.2 milestone Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays. Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants