Skip to content

Commit

Permalink
Added implementation of values (#28)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cperezln authored Jan 19, 2024
1 parent d28e93a commit eaea633
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
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",
"\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",
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

0 comments on commit eaea633

Please sign in to comment.