Description
-
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