From b4eea3accd8230094d9e81312ed3a3a70e240e85 Mon Sep 17 00:00:00 2001 From: Evan Jeffrey Date: Tue, 28 Apr 2026 19:21:57 -0700 Subject: [PATCH 1/4] Add default zero constructor for QuadPrecision Most python numeric types have default constructors, and pandas relies on it when building string representations of data frames --- src/csrc/scalar.c | 9 ++++++--- tests/test_quaddtype.py | 24 +++++++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/csrc/scalar.c b/src/csrc/scalar.c index 4d23333..9c1f960 100644 --- a/src/csrc/scalar.c +++ b/src/csrc/scalar.c @@ -281,11 +281,11 @@ QuadPrecision_from_object(PyObject *value, QuadBackendType backend) static PyObject * QuadPrecision_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) { - PyObject *value; + PyObject *value = 0; const char *backend_str = "sleef"; static char *kwlist[] = {"value", "backend", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|s", kwlist, &value, &backend_str)) { + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Os", kwlist, &value, &backend_str)) { return NULL; } @@ -298,6 +298,9 @@ QuadPrecision_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) return NULL; } + if (value == NULL) { + return (PyObject *)QuadPrecision_raw_new(backend); + } return (PyObject *)QuadPrecision_from_object(value, backend); } @@ -747,4 +750,4 @@ init_quadprecision_scalar(void) { QuadPrecision_Type.tp_base = &PyFloatingArrType_Type; return PyType_Ready(&QuadPrecision_Type); -} \ No newline at end of file +} diff --git a/tests/test_quaddtype.py b/tests/test_quaddtype.py index 0850e4b..5f0ac80 100644 --- a/tests/test_quaddtype.py +++ b/tests/test_quaddtype.py @@ -5996,4 +5996,26 @@ def test_sleef_purecfma_symbols(): for sym in purecfma_symbols[:5]: print(f" {sym}") if len(purecfma_symbols) > 5: - print(f" ... and {len(purecfma_symbols) - 5} more") \ No newline at end of file + print(f" ... and {len(purecfma_symbols) - 5} more") + + +def test_empty_construct(): + assert QuadPrecision() == QuadPrecision(0) == 0 + + +def test_pandas_strrep(): + """Test that we can construct a pandas data frame with quad precision columns + + Make sure the string representation can be generated + """ + import pandas as pd + + BIG_NUMBER=123456789098765432123456789 + x = np.arange(500, dtype=np.float64) * BIG_NUMBER + y = np.arange(500, dtype=QuadPrecDType()) * BIG_NUMBER + df = pd.DataFrame({"col1": x, "col2": y}) + assert isinstance(str(df), str) # Make sure this doesn't fail + assert df["col1"].dtype == np.float64 + assert df["col2"].dtype == QuadPrecDType() + assert df["col1"].iloc[499] != QuadPrecision(499 * BIG_NUMBER) + assert df["col2"].iloc[499] == QuadPrecision(499 * BIG_NUMBER) From ec39a023c55cda8765046cae1d86bb2220e36cc3 Mon Sep 17 00:00:00 2001 From: Evan Jeffrey Date: Tue, 28 Apr 2026 20:29:42 -0700 Subject: [PATCH 2/4] Add pandas test dependency --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e7cacba..697216e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,8 @@ dependencies = [ test = [ "pytest", "mpmath", - "pytest-run-parallel" + "pytest-run-parallel", + "pandas" ] docs = [ From ae54efa9f3899061a320a3d18a66811ed7b78309 Mon Sep 17 00:00:00 2001 From: Evan Jeffrey Date: Wed, 29 Apr 2026 20:34:26 -0700 Subject: [PATCH 3/4] Add test dependencies to big_endian and old CPU tests --- .github/workflows/big_endian.yml | 2 +- .github/workflows/test_old_cpu.yml | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/big_endian.yml b/.github/workflows/big_endian.yml index 4def7c0..528ad17 100644 --- a/.github/workflows/big_endian.yml +++ b/.github/workflows/big_endian.yml @@ -137,7 +137,7 @@ jobs: python -m pip install --break-system-packages --no-deps . -v --no-build-isolation --force-reinstall && # Install test dependencies separately - python -m pip install --break-system-packages pytest pytest-run-parallel pytest-timeout mpmath && + python -m pip install --break-system-packages .[test] && python -m pytest -vvv --color=yes --timeout=600 --tb=short tests/ '" diff --git a/.github/workflows/test_old_cpu.yml b/.github/workflows/test_old_cpu.yml index ca75cc4..491c370 100644 --- a/.github/workflows/test_old_cpu.yml +++ b/.github/workflows/test_old_cpu.yml @@ -58,6 +58,8 @@ jobs: else pip install . --no-build-isolation -v fi + # Install the test dependencies + pip install .[test] - name: Test import on ${{ matrix.cpu[1] }} run: | @@ -74,5 +76,4 @@ jobs: - name: Run tests on ${{ matrix.cpu[1] }} run: | - pip install pytest mpmath - sde -${{ matrix.cpu[0] }} -- python -m pytest tests/ -v --tb=short -v -s \ No newline at end of file + sde -${{ matrix.cpu[0] }} -- python -m pytest tests/ -v --tb=short -v -s From 840a2ffcdda2cc4e4ef79322bcedafd246852410 Mon Sep 17 00:00:00 2001 From: Evan Jeffrey Date: Wed, 29 Apr 2026 21:21:17 -0700 Subject: [PATCH 4/4] Fix to not reinstall wrong architecture package with the test dependancies --- .github/workflows/test_old_cpu.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_old_cpu.yml b/.github/workflows/test_old_cpu.yml index 491c370..476a876 100644 --- a/.github/workflows/test_old_cpu.yml +++ b/.github/workflows/test_old_cpu.yml @@ -54,12 +54,10 @@ jobs: # For Sandy Bridge (x86-64-v2), we need to disable FMA code paths # since FMA instructions are not available on that microarchitecture if [ "${{ matrix.cpu[0] }}" = "snb" ]; then - pip install . --no-build-isolation -v -Csetup-args=-Ddisable_fma=true + pip install .[test] --no-build-isolation -v -Csetup-args=-Ddisable_fma=true else - pip install . --no-build-isolation -v + pip install .[test] --no-build-isolation -v fi - # Install the test dependencies - pip install .[test] - name: Test import on ${{ matrix.cpu[1] }} run: |