From eaea6334acb812ad24d8e2bfe7a7db2276abbc9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20P=C3=A9rez=20Corral?= <69525230+cperezln@users.noreply.github.com> Date: Fri, 19 Jan 2024 09:14:10 +0100 Subject: [PATCH] Added implementation of values (#28) * Values first approach * Test changed to check pd.values against implemented values. Values optimized (to value peach) * Changed to property (as defined in pandas docs). documentation written * Changed values to property (as defined in pandas docs). values documentation written * Undone Notebook metadata changes * Minor changes in docs. Tests cover string case * Added implementation of values * Some minor corrections proposed by reviewers * Removed blank spaces. Improved tests. Merged solved * Corrected .ipynb * Linting errors solved --- docs/user-guide/advanced/Pandas_API.ipynb | 26 +++++++++++++++++++++++ src/pykx/pandas_api/pandas_meta.py | 4 ++++ tests/test_pandas_api.py | 9 ++++++++ 3 files changed, 39 insertions(+) diff --git a/docs/user-guide/advanced/Pandas_API.ipynb b/docs/user-guide/advanced/Pandas_API.ipynb index 239c4c8..3b867d6 100644 --- a/docs/user-guide/advanced/Pandas_API.ipynb +++ b/docs/user-guide/advanced/Pandas_API.ipynb @@ -353,6 +353,32 @@ "tab.size" ] }, + { + "cell_type": "markdown", + "id": "4023811f-0f23-4e4b-919c-c055b865d9d2", + "metadata": {}, + "source": [ + "### Table.values\n", + "Return a matricial representation of the DataFrame.\n", + "\n", + "Only the values in the DataFrame will be returned, the axes labels will be removed.\n", + "\n", + "**Returns:**\n", + "\n", + "| Type | Description |\n", + "| :---------------: | :------------------------------------------------------------------- |\n", + "| List | The values of the table as a matrix. |" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "a7843813-43fc-4920-acd9-6fd2dd50c32e", + "metadata": {}, + "source": [ + "tab.values" + ] + }, { "cell_type": "markdown", "id": "2be2ece3", diff --git a/src/pykx/pandas_api/pandas_meta.py b/src/pykx/pandas_api/pandas_meta.py index 39668d5..6e80339 100644 --- a/src/pykx/pandas_api/pandas_meta.py +++ b/src/pykx/pandas_api/pandas_meta.py @@ -135,6 +135,10 @@ def shape(self): def size(self): return q('{count[x] * count[cols x]}', self) + @property + def values(self): + return q('value each', self) + @api_return def mean(self, axis: int = 0, numeric_only: bool = False): tab = self diff --git a/tests/test_pandas_api.py b/tests/test_pandas_api.py index acfe55f..02befe2 100644 --- a/tests/test_pandas_api.py +++ b/tests/test_pandas_api.py @@ -59,6 +59,15 @@ def test_df_size(q): assert (df.size == df.pd().size) +def test_df_values(q): + tab = q('([]p: 10?100; s: 10?`a`b`c`d; id: 10?"abc123; nulls: 10?0n")') + pandas_table = tab.pd() + assert pandas_table.values.tolist() == tab.values.py() + tab = q('([]p: 2?100; n: (::; ::))') + pandas_table = tab.pd() + assert pandas_table.values.tolist() == tab.values.py() + + def test_df_head(kx, q): df = q('([] til 10; 10 - til 10)') assert check_result_and_type(kx, df.head(), q('5 # ([] til 10; 10 - til 10)'))