Skip to content
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

BUG: Series.get() on ExtensionArray with integer key not in index returns incorrect result #21257

Closed
Dr-Irv opened this issue May 30, 2018 · 0 comments · Fixed by #21260
Closed
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays.
Milestone

Comments

@Dr-Irv
Copy link
Contributor

Dr-Irv commented May 30, 2018

Code Sample, a copy-pastable example if possible

In [1]: import pandas as pd

In [2]: import decimal

In [3]: from pandas.tests.extension.decimal.array import DecimalArray

In [4]: s = pd.Series(DecimalArray([decimal.Decimal(i) for i in range(10)]))

In [5]: s
Out[5]:
0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8
9    9
dtype: decimal

In [6]: s2 = s[::2]

In [7]: s2
Out[7]:
0    0
2    2
4    4
6    6
8    8
dtype: decimal

In [8]: s2.get(1)
Out[8]: Decimal('2')

In [9]: t = pd.Series([i for i in range(10)], dtype=float)

In [10]: t
Out[10]:
0    0.0
1    1.0
2    2.0
3    3.0
4    4.0
5    5.0
6    6.0
7    7.0
8    8.0
9    9.0
dtype: float64

In [11]: t2 = t[::2]

In [12]: t2
Out[12]:
0    0.0
2    2.0
4    4.0
6    6.0
8    8.0
dtype: float64

In [13]: t2.get(1)

In [14]: t2.get(1) is None
Out[14]: True

Problem description

It appears that I didn't fix all of the issues in #20885, as I missed an issue when creating #20882 .

If you have an integer index backing an ExtensionArray, and you do .get(n), where n is not in the index, an incorrect result is returned.

Expected Output

In the example above, the value of s2.get(1) should be None, just as it is for t2.get(1).

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.23.0
pytest: 3.3.2
pip: 9.0.1
setuptools: 38.4.0
Cython: 0.27.3
numpy: 1.14.0
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.6.6
patsy: 0.5.0
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: 2.1.2
openpyxl: 2.4.10
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.1
pymysql: 0.7.11.None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jschendel jschendel added Bug ExtensionArray Extending pandas with custom dtypes or arrays. labels Jun 1, 2018
@jreback jreback added this to the 0.24.0 milestone Jun 29, 2018
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants