Skip to content

take_1d yields surprising results when working with SparseArray #19506

Closed
@hexgnu

Description

@hexgnu

Code Sample, a copy-pastable example if possible

import pandas as pd
import numpy as np
import pandas.core.algorithms as algos

algos.take_1d(pd.SparseArray([0,0,1], fill_value=0), [0,1,2]) #=> array([       1, 23618416,       32])

# VS

algos.take_1d(np.array([0,0,1]), [0,1,2]) #=> array([0,0,1])

Problem description

This to me smells like a problem with SparseArray sending over a sparse representation to take_1d in the C code. I would expect these values to be the same.

Expected Output

I would expect them to be the same.

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: be09289 python: 3.6.1.final.0 python-bits: 64 OS: Linux OS-release: 4.13.16-202.fc26.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

pandas: 0.23.0.dev0+205.gbe0928903
pytest: 3.3.1
pip: 9.0.1
setuptools: 28.8.0
Cython: 0.27.3
numpy: 1.13.1
scipy: 0.19.1
pyarrow: 0.8.0
xarray: 0.10.0
IPython: 6.1.0
sphinx: 1.6.5
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: 1.5.1
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: 0.4.0
matplotlib: 2.0.2
openpyxl: 2.4.9
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0b10
sqlalchemy: 1.1.15
pymysql: 0.7.11.None
psycopg2: None
jinja2: 2.9.6
s3fs: 0.1.2
fastparquet: 0.1.3
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    IndexingRelated to indexing on series/frames, not to indexes themselvesInternalsRelated to non-user accessible pandas implementationSparseSparse Data Type

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions