From eae9bfdaef48747f8ab80989109c871dc79f642c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20L=C3=B3pez-Gonz=C3=A1lez?= Date: Wed, 17 Jan 2024 16:03:50 +0100 Subject: [PATCH 1/3] Reorders cols calculation at preparse_computations --- src/pykx/pandas_api/pandas_meta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pykx/pandas_api/pandas_meta.py b/src/pykx/pandas_api/pandas_meta.py index 39668d5..3fface0 100644 --- a/src/pykx/pandas_api/pandas_meta.py +++ b/src/pykx/pandas_api/pandas_meta.py @@ -50,9 +50,9 @@ def _get_bool_only_subtable(tab): def preparse_computations(tab, axis=0, skipna=True, numeric_only=False, bool_only=False): - cols = q('cols', tab) if 'Keyed' in str(type(tab)): tab = q('{(keys x) _ 0!x}', tab) + cols = q('cols', tab) if numeric_only: (tab, cols) = _get_numeric_only_subtable_with_bools(tab) if bool_only: From 28214adc862dd6dd6f61dadd1c076f19fffd7aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20L=C3=B3pez-Gonz=C3=A1lez?= Date: Wed, 17 Jan 2024 16:34:14 +0100 Subject: [PATCH 2/3] Adds a `max` test with keyed table and axis=0 --- tests/test_pandas_api.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_pandas_api.py b/tests/test_pandas_api.py index acfe55f..993af23 100644 --- a/tests/test_pandas_api.py +++ b/tests/test_pandas_api.py @@ -1810,6 +1810,15 @@ def test_pandas_max(q): for i in range(100): assert float(qmax[i]) == float(pmax[i]) + ktab = q('{1!x}', tab) + df = ktab.pd() + + qmax = ktab.max().py() + pmax = df.max() + + assert float(pmax['price']) == qmax['price'] + assert float(pmax['ints']) == qmax['ints'] + def test_pandas_all(q): tab = q( From f9903e838947a82cedfba626b081cde9aaae6bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20L=C3=B3pez-Gonz=C3=A1lez?= Date: Wed, 17 Jan 2024 17:42:11 +0100 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: rianoc-kx <46995503+rianoc-kx@users.noreply.github.com> --- src/pykx/pandas_api/pandas_meta.py | 4 ++-- tests/test_pandas_api.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pykx/pandas_api/pandas_meta.py b/src/pykx/pandas_api/pandas_meta.py index 3fface0..91cc147 100644 --- a/src/pykx/pandas_api/pandas_meta.py +++ b/src/pykx/pandas_api/pandas_meta.py @@ -51,8 +51,8 @@ def _get_bool_only_subtable(tab): def preparse_computations(tab, axis=0, skipna=True, numeric_only=False, bool_only=False): if 'Keyed' in str(type(tab)): - tab = q('{(keys x) _ 0!x}', tab) - cols = q('cols', tab) + tab = tab.values() + cols = tab.columns if numeric_only: (tab, cols) = _get_numeric_only_subtable_with_bools(tab) if bool_only: diff --git a/tests/test_pandas_api.py b/tests/test_pandas_api.py index 993af23..d1247ea 100644 --- a/tests/test_pandas_api.py +++ b/tests/test_pandas_api.py @@ -1810,7 +1810,7 @@ def test_pandas_max(q): for i in range(100): assert float(qmax[i]) == float(pmax[i]) - ktab = q('{1!x}', tab) + ktab = tab.set_index('sym') df = ktab.pd() qmax = ktab.max().py()