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 | Rows of the table, each as a list. |"
cperezln marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
"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
5 changes: 5 additions & 0 deletions src/pykx/pandas_api/pandas_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ def shape(self):
@property
def size(self):
return q('{count[x] * count[cols x]}', self)

cperezln marked this conversation as resolved.
Show resolved Hide resolved
@property
def values(self):
tab = self
cperezln marked this conversation as resolved.
Show resolved Hide resolved
return q('value peach', tab)
cperezln marked this conversation as resolved.
Show resolved Hide resolved

@api_return
def mean(self, axis: int = 0, numeric_only: bool = False):
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 @@ -2029,3 +2029,12 @@ def test_keyed_loc_fixes(q):
mkt[['k1', 'y']]
with pytest.raises(KeyError):
mkt['k1']

def test_values(q):
cperezln marked this conversation as resolved.
Show resolved Hide resolved
cperezln marked this conversation as resolved.
Show resolved Hide resolved
col1 = q('10?100')
col2 = q('10?`a`b`c`d')
col3 = q('10?`x`y`z`1`2`3')
tab = q('{[price; sym; id] ([]p: price; s: sym; i: string id)}', col1, col2, col3)
cperezln marked this conversation as resolved.
Show resolved Hide resolved
q_table = tab
cperezln marked this conversation as resolved.
Show resolved Hide resolved
pandas_table = tab.pd()
assert pandas_table.values.tolist() == q_table.values.py()
nipsn marked this conversation as resolved.
Show resolved Hide resolved