Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added implementation of values #28

Merged
merged 13 commits into from
Jan 19, 2024
26 changes: 26 additions & 0 deletions docs/user-guide/advanced/Pandas_API.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
cperezln marked this conversation as resolved.
Show resolved Hide resolved
"\n",
"| Type | Description |\n",
"| :---------------: | :------------------------------------------------------------------- |\n",
"| List | The values of the table as a matrix. |"
]
},
{
"cell_type": "code",
"execution_count": 2,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of execution_count should be null, like in the others code cells

"id": "a7843813-43fc-4920-acd9-6fd2dd50c32e",
"metadata": {},
"source": [
"tab.values"
]
},
{
"cell_type": "markdown",
"id": "2be2ece3",
Expand Down
4 changes: 4 additions & 0 deletions src/pykx/pandas_api/pandas_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/test_pandas_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)'))
Expand Down