pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
43.74k stars 17.95k forks source link

BUG: aggregations.pyx importing signbit() and sqrt() #51047

Open he32 opened 1 year ago

he32 commented 1 year ago

Pandas version checks

Reproducible Example

While trying to build this on NetBSD, the following appears in the build log:

pandas/_libs/window/aggregations.cpp: In function 'void __pyx_f_6pandas_5_libs_6window_12aggregations_add_mean(__pyx_t_5numpy_float64_t, Py_ssize_t*, __pyx_t_5numpy_float64_t*, Py_ssize_t*, __pyx_t_5numpy_float64_t*, __pyx_t_5numpy_int64_t*, __pyx_t_5numpy_float64_t*)':
pandas/_libs/window/aggregations.cpp:4784:18: error: 'signbit' was not declared in this scope; did you mean 'std::signbit'?
 4784 |     __pyx_t_1 = (signbit(__pyx_v_val) != 0);
      |                  ^~~~~~~
      |                  std::signbit

This happens both on NetBSD/amd64 and NetBSD/powerpc, with pandas version 1.5.3.

Issue Description

See above for the build error.

The reason for this build failure on NetBSD is that even though <math.h> is included, the <complex> C++ header is included later, and that includes <cmath> which #undefs the macros defined in <math.h>, among them signbit(). So at this point, you have to use the std::signbit variant instead, and this has consequences for how those functions should be imported into the aggregations.pyx file. This used to be OK in pandas version 1.3.5, but things have changed in 1.5.3 so that this no longer builds on NetBSD.

I have a suggested change lined up which re-does the import of signbit() and sqrt() to come from the std:: namespace, but don't know if there is a particular reason the change between 1.3.5 and 1.5.3 was introduced.

Expected Behavior

The build should succeed.

Installed Versions

INSTALLED VERSIONS ------------------ commit : 2e218d10984e9919f0296931d92ea851c6a6faf5 python : 3.10.8.final.0 python-bits : 64 OS : NetBSD OS-release : 9.99.104 Version : NetBSD 9.99.104 (GENERIC) #2: Wed Nov 2 15:11:41 UTC 2022 he@whatever.no:/usr/obj/sys/arch/amd64/compile/GENERIC machine : amd64 processor : x86_64 byteorder : little LC_ALL : None LANG : None LOCALE : en_US.UTF-8 pandas : 1.5.3 numpy : 1.23.4 pytz : 2022.1 dateutil : 2.8.2 setuptools : 63.4.3 pip : 22.3.1 Cython : 0.29.32 pytest : 7.2.0 hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : 4.9.1 html5lib : None pymysql : None psycopg2 : None jinja2 : 3.1.2 IPython : None pandas_datareader: None bs4 : None bottleneck : 1.3.5 brotli : 1.0.9 fastparquet : None fsspec : None gcsfs : None matplotlib : 3.6.2 numba : None numexpr : 2.8.4 odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pyreadstat : None pyxlsb : None s3fs : None scipy : 1.9.3 snappy : None sqlalchemy : None tables : 3.7.0 tabulate : None xarray : None xlrd : None xlwt : None zstandard : None tzdata : None
iansheng commented 1 year ago

Hi, I ran into the same problem as you. Any progress so far?

he32 commented 1 year ago

Hi, I ran into the same problem as you. Any progress so far?

Sorry, as I just posted to that thread, I ran out of energy trying to understand what else was being suggested as a fix for the problem.

Regards,

barracuda156 commented 10 months ago

Same error on MacOS PowerPC:

/usr/bin/gcc-4.2 -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -pipe -Os -arch ppc -isysroot/ -DNPY_NO_DEPRECATED_API=0 -Ipandas/_libs/window -I/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/numpy/core/include -I/opt/local/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c pandas/_libs/window/aggregations.cpp -o build/temp.macosx-10.6-ppc-cpython-311/pandas/_libs/window/aggregations.o -Wno-error=unreachable-code
pandas/_libs/window/aggregations.cpp: In function ‘void __pyx_f_6pandas_5_libs_6window_12aggregations_add_mean(__pyx_t_5numpy_float64_t, Py_ssize_t*, __pyx_t_5numpy_float64_t*, Py_ssize_t*, __pyx_t_5numpy_float64_t*, __pyx_t_5numpy_int64_t*, __pyx_t_5numpy_float64_t*)’:
pandas/_libs/window/aggregations.cpp:4800: error: ‘signbit’ was not declared in this scope
pandas/_libs/window/aggregations.cpp: In function ‘void __pyx_f_6pandas_5_libs_6window_12aggregations_remove_mean(__pyx_t_5numpy_float64_t, Py_ssize_t*, __pyx_t_5numpy_float64_t*, Py_ssize_t*, __pyx_t_5numpy_float64_t*)’:
pandas/_libs/window/aggregations.cpp:4967: error: ‘signbit’ was not declared in this scope
error: command '/usr/bin/gcc-4.2' failed with exit code 1
barracuda156 commented 10 months ago

Possibly related: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14608 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=44611

newacct commented 1 month ago

I have this problem on pandas 1.5.0, but not on 1.4.4. I tracked it down to this commit, from this pull request. This issue says that that pull request removed too much, and causes the signbit() problem, which is the problem we are seeing here.