lmmentel / mendeleev

A python package for accessing various properties of elements, ions and isotopes in the periodic table of elements.
https://mendeleev.readthedocs.io
MIT License
225 stars 43 forks source link

df = fetch_table('elements') its not working its showing the error AttributeError: 'OptionEngine' object has no attribute 'execute' #158

Closed 93-hsngit closed 5 months ago

93-hsngit commented 5 months ago

Describe the bug

from mendeleev.fetch import fetch_table from mendeleev.db import get_session, get_engine

df = fetch_table('elements')

AttributeError: 'OptionEngine' object has no attribute 'execute'

93-hsngit commented 5 months ago

AttributeError: 'OptionEngine' object has no attribute 'execute'

lmmentel commented 5 months ago

Thanks @93-hsngit, could you say what version of mendeleev you are using?

lmmentel commented 5 months ago

I just tried to reproduce with the latest version (0.16.2) and didn't get any errors:

In [1]: from mendeleev.fetch import fetch_table, get_engine

In [2]: df = fetch_table("elements")

In [3]: df.head()
Out[3]: 
                                          annotation  atomic_number  atomic_radius  atomic_volume block  ...  mendeleev_number dipole_polarizability_unc  pettifor_number  glawe_number molar_heat_capacity
0  density(@ -253C), evaporation_heat(H-H), fusio...              1           25.0           14.1     s  ...               105                   0.00003            103.0         103.0              28.836
1                                 density(@ -270C),               2          120.0           31.8     s  ...               112                   0.00002              1.0           1.0              20.786
2                                                                 3          145.0           13.1     s  ...                 1                   0.00050             12.0          12.0              24.860
3                                                                 4          105.0            5.0     s  ...                75                   0.03000             77.0          77.0              16.443
4                                                                 5           85.0            4.6     p  ...                81                   0.10000             86.0          86.0              11.087

[5 rows x 69 columns]

In [4]: import mendeleev

In [5]: mendeleev.__version__
Out[5]: '0.16.2'
93-hsngit commented 5 months ago

I am Using the latest version.

On Mon, May 27, 2024, 9:01 PM Lukasz Mentel @.***> wrote:

I just tried to reproduce with the latest version (0.16.2) and didn't get any errors:

In [1]: from mendeleev.fetch import fetch_table, get_engine In [2]: df = fetch_table("elements") In [3]: df.head()Out[3]: annotation atomic_number atomic_radius atomic_volume block ... mendeleev_number dipole_polarizability_unc pettifor_number glawe_number molar_heat_capacity0 density(@ -253C), evaporation_heat(H-H), fusio... 1 25.0 14.1 s ... 105 0.00003 103.0 103.0 28.8361 density(@ -270C), 2 120.0 31.8 s ... 112 0.00002 1.0 1.0 20.7862 3 145.0 13.1 s ... 1 0.00050 12.0 12.0 24.8603 4 105.0 5.0 s ... 75 0.03000 77.0 77.0 16.4434 5 85.0 4.6 p ... 81 0.10000 86.0 86.0 11.087

[5 rows x 69 columns] In [4]: import mendeleev In [5]: mendeleev.versionOut[5]: '0.16.2'

— Reply to this email directly, view it on GitHub https://github.com/lmmentel/mendeleev/issues/158#issuecomment-2133702765, or unsubscribe https://github.com/notifications/unsubscribe-auth/BH3U5Q3CEBX5RRJIERH3XATZENGU5AVCNFSM6AAAAABIKPOQRGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZTG4YDENZWGU . You are receiving this because you were mentioned.Message ID: @.***>

lmmentel commented 5 months ago

Just to be sure, could you share what the following code produces with your installation:

import mendeleev
import sqlalchemy
import pandas
print(f"{mendeleev.__version__=}")
print(f"{sqlalchemy.__version__=}")
print(f"{pandas.__version__=}")
lmmentel commented 5 months ago

I googled around and discovered this might be related to sqlachemy version. I cannot reproduce your exact error but when I downgraded to sqlalchemy==1.4.52 I get this:

from mendeleev.fetch import fetch_table, get_engine
df = fetch_table("elements")
...
AttributeError: 'Engine' object has no attribute 'cursor'

which seems to be a known issue with pandas and sqlalchemy https://github.com/pandas-dev/pandas/issues/57049.

When you get a chance please share the versions of packages you're using, see previous comment https://github.com/lmmentel/mendeleev/issues/158#issuecomment-2133810359

93-hsngit commented 5 months ago

Please see the error

[image: image.png] I import all the required mendeleev libraries (and in my pc sqlalchemy==2.0.23) [image: image.png] Please help.

Regards Hossain

On Tue, May 28, 2024 at 1:10 AM Lukasz Mentel @.***> wrote:

I googled around and discovered this might be related to sqlachemy version. I cannot reproduce your exact error but when I downgraded to sqlalchemy==1.4.52 I get this:

...AttributeError: 'Engine' object has no attribute 'cursor'

— Reply to this email directly, view it on GitHub https://github.com/lmmentel/mendeleev/issues/158#issuecomment-2133977550, or unsubscribe https://github.com/notifications/unsubscribe-auth/BH3U5Q2TDFFLXSVZVWWFGUDZEODZ3AVCNFSM6AAAAABIKPOQRGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZTHE3TONJVGA . You are receiving this because you were mentioned.Message ID: @.***>

lmmentel commented 5 months ago

@93-hsngit there is no image attached to your comment, maybe something went wrong?

Right now I cannot reproduce your specific error and my suspicion is that it's something to do with dependencies so please share the output of running https://github.com/lmmentel/mendeleev/issues/158#issuecomment-2133810359

93-hsngit commented 5 months ago

mendeleev.version='0.16.2' sqlalchemy.version='2.0.25' pandas.version='1.5.3'

lmmentel commented 5 months ago

Thanks @93-hsngit, I was able to reproduce the same error with the combination of dependencies you shared.

I started working on a solution in #159 but it might take some time to test against relevant versions of dependencies. Overall this seems like a mismatch between major version of pandas and sqlalchemy but I hope I can find an api consistent between the version changes.

In the meantime you could upgrade your pandas versions to ">=2.0.0" and that should solve it for you.

93-hsngit commented 5 months ago

Yahh..., now the problem get resolve after installing pandas==2.0.0, Thank you so much @lmmentel Love your work