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

DataFrame.from_records ignores exclude if it is [0] #18679

Open
pfmoore opened this issue Dec 7, 2017 · 2 comments
Open

DataFrame.from_records ignores exclude if it is [0] #18679

pfmoore opened this issue Dec 7, 2017 · 2 comments
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors

Comments

@pfmoore
Copy link

pfmoore commented Dec 7, 2017

Code Sample, a copy-pastable example if possible

df1 = pd.DataFrame.from_records([[1,2,3],[4,5,6],[7,8,9]], index=0, exclude=[0])
df2 = pd.DataFrame.from_records([[1,2,3],[4,5,6],[7,8,9]], index=0)

Problem description

In both cases, the data frame has columns 0, 1 and 2. If you use an index of 1, or exclude=[1], the columns are (correctly) [0, 2].

The issue is caused by the any() call at https://github.com/pandas-dev/pandas/blob/master/pandas/core/frame.py#L1178 which treats a zero column ID as false. Changing this to if exclude fixes the problem for me (by running the code to drop columns if the exclude set is not empty).

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.2.final.0 python-bits: 64 OS: Windows OS-release: 7 machine: AMD64 processor: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None

pandas: 0.21.0
pytest: None
pip: 9.0.1
setuptools: 38.2.4
Cython: None
numpy: 1.13.3
scipy: None
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.0
openpyxl: 2.4.9
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0b10
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@sinhrks sinhrks added Bug IO Data IO issues that don't fit into a more specific label labels Dec 25, 2017
@jreback jreback added this to the 0.23.0 milestone Dec 26, 2017
@jreback jreback modified the milestones: 0.23.0, Next Major Release Apr 14, 2018
@OmerJog
Copy link

OmerJog commented Mar 4, 2019

still an issue

@TomAugspurger
Copy link
Contributor

Still open, if you're interested in submitting a PR @OmerJog.

@mroeschke mroeschke added Constructors Series/DataFrame/Index/pd.array Constructors and removed IO Data IO issues that don't fit into a more specific label labels May 2, 2020
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Constructors Series/DataFrame/Index/pd.array Constructors
Projects
None yet
Development

No branches or pull requests

6 participants