Skip to content

BUG: Numexpr engine - Name of the returned series dropped when using user function in DataFrame.eval #58069

Closed
@domsmrz

Description

@domsmrz

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

def rename_to_foo(s):
  return s.rename('foo')
df = pd.Series([1,2], name='bar').to_frame()
sr = df.eval('@rename_to_foo(bar)', engine='numexpr')
print(sr.name)

## Different example:
import numpy as np
floor = np.floor
df = pd.Series([0.2, 1.5, 2.8], name='baz').to_frame
sr = df.eval('@floor(baz)', engine='numexpr')
print(sr.name)

Issue Description

When running with numexpr engine, the name of the returned series (sr) is None even though it should be foo in the first example and baz in the second. This creates discrepancies between using my_func(df['foo']) and df.eval('@my_func(foo)') where the former preserves the correct name.

Note that this is an issue when using engine='numexpr' only. Using engine='python' preserves the name.

Expected Behavior

Names of the series to be preserved (i.e., sr.name == "foo" in the first case and sr.name == "baz" in the second).

Installed Versions

INSTALLED VERSIONS

commit : 2e218d1
python : 3.11.7.final.0
python-bits : 64
OS : Linux
OS-release : 6.6.13-1rodete3-amd64
Version : #1 SMP PREEMPT_DYNAMIC Debian 6.6.13-1rodete3 (2024-03-04)
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.3
numpy : 1.24.2
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.1.2
pip : 23.3
Cython : 3.0.8
pytest : 7.4.4
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 5.1.0
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.20.0
pandas_datareader: None
bs4 : 4.12.3
bottleneck : 1.3.5
brotli : 1.1.0
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.6.3
numba : 0.57.1
numexpr : 2.9.0
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
snappy :
sqlalchemy : None
tables : 3.7.0
tabulate : None
xarray : None
xlrd : 2.0.1
xlwt : None
zstandard : None
tzdata : None

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions