Azure / azure-kusto-python

Kusto client libraries for Python
MIT License
184 stars 107 forks source link

AttributeError: `np.NaN` was removed in the NumPy 2.0 release. Use `np.nan` instead #541

Closed debonte closed 5 months ago

debonte commented 5 months ago

Code Sample, a copy-pastable example if possible

def run_kql(client: KustoClient, query: str, database: str) -> pd.DataFrame:
    response = client.execute(database, query)
    return dataframe_from_result_table(response.primary_results[0])

Problem description

Numpy 2.0 shipped over the weekend. My dashboard automatically upgraded to 2.0 and, when using azure-kusto-data 4.4.1, I'm getting the following error from dataframe_from_result_table:

AttributeError: `np.NaN` was removed in the NumPy 2.0 release. Use `np.nan` instead.

np.nan is also available in earlier versions of numpy. Well, at least in the latest 1.x version (1.26.4). So I think it may be safe for you to just use np.nan instead of np.NaN regardless of the numpy version in use.

Some more context:

File ~/work/pyrx/pyrx/dashboard/chart_utils.py:21, in run_kql(client, query, database)
     19 def run_kql(client: KustoClient, query: str, database: str = "VSCodeExt") -> pd.DataFrame:
     20     response = client.execute(database, query)
---> 21     return dataframe_from_result_table(response.primary_results[0])

File /opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/azure/kusto/data/helpers.py:63, in dataframe_from_result_table(table, nullable_bools)
     61     frame[col.column_name] = frame[col.column_name].astype(pd.Int64Dtype())
     62 elif col.column_type == "real" or col.column_type == "decimal":
---> 63     frame[col.column_name] = frame[col.column_name].replace("NaN", np.NaN).replace("Infinity", np.PINF).replace("-Infinity", np.NINF)
     64     frame[col.column_name] = pd.to_numeric(frame[col.column_name], errors="coerce").astype(pd.Float64Dtype())
     65 elif col.column_type == "datetime":
     66     # Pandas before version 2 doesn't support the "format" arg

File /opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/numpy/__init__.py:397, in __getattr__(attr)
    394     raise AttributeError(__former_attrs__[attr])
    396 if attr in __expired_attributes__:
--> 397     raise AttributeError(
    398         f"`np.{attr}` was removed in the NumPy 2.0 release. "
    399         f"{__expired_attributes__[attr]}"
    400     )
    402 if attr == "chararray":
    403     warnings.warn(
    404         "`np.chararray` is deprecated and will be removed from "
    405         "the main namespace in the future. Use an array with a string "
    406         "or bytes dtype instead.", DeprecationWarning, stacklevel=2)

Output of pip freeze

accessible-pygments==0.0.5 alabaster==0.7.16 altair==5.3.0 anyio==4.4.0 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 arrow==1.3.0 asttokens==2.4.1 async-lru==2.0.4 attrs==23.2.0 azure-core==1.30.2 azure-data-tables==12.5.0 azure-identity==1.16.1 azure-kusto-data==4.4.1 Babel==2.15.0 beautifulsoup4==4.12.3 bleach==6.1.0 bokeh==2.4.3 certifi==2024.6.2 cffi==1.16.0 charset-normalizer==3.3.2 click==8.1.7 colorama==0.4.6 comm==0.2.2 contourpy==1.2.1 cryptography==42.0.8 cycler==0.12.1 debugpy==1.8.1 decorator==5.1.1 defusedxml==0.7.1 Deprecated==1.2.14 docutils==0.20.1 executing==2.0.1 fastjsonschema==2.20.0 fonttools==4.53.0 fqdn==1.5.1 greenlet==3.0.3 h11==0.14.0 httpcore==1.0.5 httpx==0.27.0 idna==3.7 ijson==3.3.0 imagesize==1.4.1 importlib_metadata==7.1.0 ipykernel==6.29.4 ipython==8.25.0 ipywidgets==8.1.3 isodate==0.6.1 isoduration==20.11.0 jedi==0.19.1 Jinja2==3.1.4 json5==0.9.25 jsonpointer==3.0.0 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 jupyter==1.0.0 jupyter-book==1.0.0 jupyter-cache==1.0.0 jupyter-console==6.6.3 jupyter-events==0.10.0 jupyter-lsp==2.2.5 jupyter_bokeh==3.0.5 jupyter_client==8.6.2 jupyter_core==5.7.2 jupyter_server==2.14.1 jupyter_server_terminals==0.5.3 jupyterlab==4.2.2 jupyterlab_pygments==0.3.0 jupyterlab_server==2.27.2 jupyterlab_widgets==3.0.11 kiwisolver==1.4.5 latexcodec==3.0.0 linkify-it-py==2.0.3 Markdown==3.6 markdown-it-py==3.0.0 MarkupSafe==2.1.5 matplotlib==3.9.0 matplotlib-inline==0.1.7 mdit-py-plugins==0.4.1 mdurl==0.1.2 mistune==3.0.2 msal==1.28.1 msal-extensions==1.1.0 multidict==6.0.5 myst-nb==1.1.0 myst-parser==2.0.0 nbclient==0.10.0 nbconvert==7.16.4 nbformat==5.10.4 nest-asyncio==1.6.0 notebook==7.2.1 notebook_shim==0.2.4 numpy==1.26.4 overrides==7.7.0 packaging==24.1 pandas==2.2.2 pandocfilters==1.5.1 panel==0.14.3 param==1.13.0 parso==0.8.4 pillow==10.3.0 platformdirs==4.2.2 plotly==5.19.0 portalocker==2.8.2 prometheus_client==0.20.0 prompt_toolkit==3.0.47 psutil==5.9.8 pure-eval==0.2.2 pybtex==0.24.0 pybtex-docutils==1.0.3 pycparser==2.22 pyct==0.5.0 pydata-sphinx-theme==0.15.3 PyGithub==1.59.0 Pygments==2.18.0 PyJWT==2.8.0 PyNaCl==1.5.0 pyparsing==3.1.2 python-dateutil==2.9.0.post0 python-json-logger==2.0.7 pytz==2024.1 pyviz_comms==3.0.2 pywin32==306 pywinpty==2.0.13 PyYAML==6.0.1 pyzmq==26.0.3 qtconsole==5.5.2 QtPy==2.4.1 referencing==0.35.1 requests==2.32.3 rfc3339-validator==0.1.4 rfc3986-validator==0.1.1 rpds-py==0.18.1 Send2Trash==1.8.3 setuptools==70.0.0 six==1.16.0 sniffio==1.3.1 snowballstemmer==2.2.0 soupsieve==2.5 sourcemap==0.2.1 Sphinx==7.3.7 sphinx-book-theme==1.1.3 sphinx-comments==0.0.3 sphinx-copybutton==0.5.2 sphinx-jupyterbook-latex==1.0.0 sphinx-multitoc-numbering==0.1.3 sphinx-thebe==0.3.1 sphinx-togglebutton==0.3.2 sphinx_design==0.6.0 sphinx_external_toc==1.0.1 sphinxcontrib-applehelp==1.0.8 sphinxcontrib-bibtex==2.6.2 sphinxcontrib-devhelp==1.0.6 sphinxcontrib-htmlhelp==2.0.5 sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.7 sphinxcontrib-serializinghtml==1.1.10 SQLAlchemy==2.0.30 stack-data==0.6.3 tabulate==0.9.0 tenacity==8.4.1 terminado==0.18.1 tinycss2==1.3.0 toolz==0.12.1 tornado==6.4.1 tqdm==4.66.4 traitlets==5.14.3 types-python-dateutil==2.9.0.20240316 typing_extensions==4.12.2 tzdata==2024.1 uc-micro-py==1.0.3 uri-template==1.3.0 urllib3==2.2.2 wcwidth==0.2.13 webcolors==24.6.0 webencodings==0.5.1 websocket-client==1.8.0 wheel==0.43.0 widgetsnbextension==4.0.11 wrapt==1.16.0 yarl==1.9.4 zipp==3.19.2
AsafMah commented 5 months ago

Already merged to master, expect a fixed version by tomorrow

AsafMah commented 5 months ago

Released 4.5.0 with the fix.