From 82d276d5adb7e1a61b376baa47f5d4321e1f7843 Mon Sep 17 00:00:00 2001 From: cperezln Date: Thu, 21 Dec 2023 09:41:16 +0100 Subject: [PATCH] Values first approach --- src/pykx/pandas_api/pandas_meta.py | 5 +++++ tests/test_pandas_api.py | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/src/pykx/pandas_api/pandas_meta.py b/src/pykx/pandas_api/pandas_meta.py index 39668d5..2754fa9 100644 --- a/src/pykx/pandas_api/pandas_meta.py +++ b/src/pykx/pandas_api/pandas_meta.py @@ -257,6 +257,11 @@ def sum(self, axis=0, skipna=True, numeric_only=False, min_count=0): min_count ), cols) + @api_return + def values(self, skipna = True, numeric_only = False): + tab = self + return q('{[table] flip value flip table}', tab) + def agg(self, func, axis=0, *args, **kwargs): # noqa: C901 if 'KeyedTable' in str(type(self)): raise NotImplementedError("'agg' method not presently supported for KeyedTable") diff --git a/tests/test_pandas_api.py b/tests/test_pandas_api.py index acfe55f..d2a6f91 100644 --- a/tests/test_pandas_api.py +++ b/tests/test_pandas_api.py @@ -2029,3 +2029,11 @@ def test_keyed_loc_fixes(q): mkt[['k1', 'y']] with pytest.raises(KeyError): mkt['k1'] + +def test_values(q): + col1 = q('10?100') + col2 = q('10?`a`b`c`d') + col3 = q('10?`x`y`z`1`2`3') + matrix = q('{[r1; r2; r3] flip enlist[r1; r2; r3]}', col1, col2, col3) + tab = q('{[price; sym; id] ([]p: price; s: sym; i: id)}', col1, col2, col3) + assert tab.values().py() == matrix.py()