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

BUG: NameError: name 'pa' is not defined despite pyarrow is installed #60573

Open
3 tasks done
emmansh opened this issue Dec 15, 2024 · 3 comments
Open
3 tasks done

BUG: NameError: name 'pa' is not defined despite pyarrow is installed #60573

emmansh opened this issue Dec 15, 2024 · 3 comments
Labels
Arrow pyarrow functionality Bug Needs Info Clarification about behavior needed to assess issue

Comments

@emmansh
Copy link

emmansh commented Dec 15, 2024

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
import pyarrow as pa

data = {
    "foo": ["A", "B", "C"],
    "prop": [0.5, 0.8, 0.7]
}

df = pd.DataFrame(data)

df["prop"].astype('float64[pyarrow]')

Issue Description

Cannot change a column type to float64[pyarrow]. The error I get is:

NameError: name 'pa' is not defined

Expected Behavior

I'd expect to get the column converted properly

0    0.5
1    0.8
2    0.7
Name: prop, dtype: double[pyarrow]

Installed Versions

INSTALLED VERSIONS

commit : 0691c5c
python : 3.12.8
python-bits : 64
OS : Darwin
OS-release : 24.1.0
Version : Darwin Kernel Version 24.1.0: Thu Oct 10 21:02:45 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T8112
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8

pandas : 2.2.3
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.9.0.post0
pip : 24.2
Cython : None
sphinx : None
IPython : 8.27.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
blosc : None
bottleneck : 1.4.2
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : 3.1.4
lxml.etree : None
matplotlib : 3.9.2
numba : None
numexpr : 2.10.1
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 17.0.0
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

@emmansh emmansh added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 15, 2024
@emmansh
Copy link
Author

emmansh commented Dec 15, 2024

Seems related to #57928.

@rhshadrach
Copy link
Member

Thanks for the report, cannot reproduce on main nor 2.2.x. Just prior to the astype line, can you try running:

import sys
print([e for e in sys.modules if "pyarrow" in e])

what is the output that you get?

@rhshadrach rhshadrach added Needs Info Clarification about behavior needed to assess issue Arrow pyarrow functionality and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 15, 2024
@emmansh
Copy link
Author

emmansh commented Dec 16, 2024

@rhshadrach

import sys
print([e for e in sys.modules if "pyarrow" in e])

## ['pandas.compat.pyarrow', 'pyarrow._generated_version', 'pyarrow.util', 'pyarrow.lib', 'pyarrow.ipc', 'pyarrow.types', 'pyarrow']

It's also worth noting that this issue is replicated on two different machines (locally as above; and AWS Sagemaker notebook).

More info
I set up my virtual env this way:

conda create -n "foo" python=3.12

source activate base
source activate foo

conda install jupyterlab pandas seaborn matplotlib pyarrow

👆🏻And working inside foo virtual env results with the issue reported in my original post.

However
if I set the virtual env in the following way, no issue and works as expected:

conda create -n "bar" python=3.12

source activate base
source activate bar

conda install jupyterlab pandas=2.2.2 seaborn matplotlib pyarrow=17.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arrow pyarrow functionality Bug Needs Info Clarification about behavior needed to assess issue
Projects
None yet
Development

No branches or pull requests

2 participants