machow / siuba

Python library for using dplyr like syntax with pandas and SQL
https://siuba.org
MIT License
1.14k stars 48 forks source link

AttributeError: module 'sqlalchemy.sql.base' has no attribute 'ImmutableColumnCollection' #473

Open christophscheuch opened 1 year ago

christophscheuch commented 1 year ago

I tried to replicate the minimal example from the website using an in-memory SQLite database:

from siuba import _, tbl, group_by, filter
from siuba.data import cars

# setup ----
from sqlalchemy import create_engine

engine = create_engine("sqlite:///:memory:")
cars.to_sql("cars", engine, index=False)

# analysis ----
(tbl(engine, "cars")
    >> group_by(_.cyl)
    >> filter(_.mpg < _.mpg.mean())
)

I get the following error:

AttributeError: module 'sqlalchemy.sql.base' has no attribute 'ImmutableColumnCollection'

Also the direct import does not work as this chunk

from sqlalchemy.sql.base import ImmutableColumnCollection

returns

ImportError: cannot import name 'ImmutableColumnCollection' from 'sqlalchemy.sql.base'

I guess it is related to this recent commit where they renamend it to ReadOnlyColumnCollection: https://github.com/sqlalchemy/sqlalchemy/commit/4e754a8914a1c2c16c97bdf363d2e24bfa823730#diff-31621fcf3d90e3d9b15029c8dc1ccbf0b7c9f320a0d04471ec0e68ae02e4ec78L1502

I'm sorry in case I miss something completely obvious. I just discovered siuba and found it appealing as an experienced R, but unfortunately I did not get far yet :(

GitHunter0 commented 1 year ago

@christophscheuch , it is because siuba is using an old version of sqlalchemy package. Try installing version 1.4.32 (pip install sqlalchemy==1.4.32). For me, that worked.