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

Cannot create a DataFrame from list subclass #21226

Closed
mitar opened this issue May 28, 2018 · 6 comments

Comments

Projects
None yet
4 participants
@mitar
Copy link
Contributor

commented May 28, 2018

Code Sample, a copy-pastable example if possible

import pandas

class List(list):
    pass

pandas.DataFrame(List([List([1,2,3]), List([4,5,6])]))
TypeError: Argument 'rows' has incorrect type (expected list, got List)

Problem description

It seems it is not possible to create a DataFrame from subclasses of lists. The code seems to have a too strict check.

Expected Output

It should create a DataFrame like it would with regular lists.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.13.0-41-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.22.0
pytest: 3.3.0
pip: 9.0.1
setuptools: 39.1.0
Cython: 0.28.2
numpy: 1.14.3
scipy: 1.0.0
pyarrow: 0.9.0
xarray: None
IPython: 6.2.1
sphinx: 1.7.4
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.999999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.4
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jorisvandenbossche

This comment has been minimized.

Copy link
Member

commented May 28, 2018

It's not a too strict check in itself, but we have typed cython code that does this conversion of lists to array. And it is that code that expects an actual list.
I don't know if having this typed actually gives a speed-up or not.

@mitar

This comment has been minimized.

Copy link
Contributor Author

commented May 28, 2018

I mean, even if it is faster if just lists is provided to cython, it should still just work if it is a subclass, no?

@Chhamanshu

This comment has been minimized.

Copy link

commented May 28, 2018

import pandas as pd
class lis():
def l1(x):
x=[45,67,89,9]
m=[67,89,23,45]
y=pd.DataFrame(x, m)
print(y)

a=lis()
a.l1()

@Chhamanshu

This comment has been minimized.

Copy link

commented May 28, 2018

import pandas as pd
class lis():
def l1(x):
x={'a':[1,4,7,8],'b':[77,88,99,55]}
y=pd.DataFrame(x)
print(y)

a=lis()
a.l1()

@Chhamanshu

This comment has been minimized.

Copy link

commented May 28, 2018

import pandas as pd
class lis():
def l1(x):
a=[1,4,7,8]
b=[77,88,99,55]
y=pd.DataFrame({'a':a,'b':b})
print(y)

a=lis()
a.l1()

mitar added a commit to mitar/pandas that referenced this issue May 29, 2018

mitar added a commit to mitar/pandas that referenced this issue May 29, 2018

@mitar

This comment has been minimized.

Copy link
Contributor Author

commented May 29, 2018

Made merge request: #21238

mitar added a commit to mitar/pandas that referenced this issue May 29, 2018

mitar added a commit to mitar/pandas that referenced this issue May 29, 2018

rok added a commit to mitar/pandas that referenced this issue Dec 14, 2018

rok added a commit to mitar/pandas that referenced this issue Dec 14, 2018

@jreback jreback added this to the 0.24.0 milestone Dec 14, 2018

rok added a commit to mitar/pandas that referenced this issue Dec 14, 2018

jreback added a commit that referenced this issue Dec 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.