Skip to content

Commit

Permalink
add skew implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
neutropolis authored and Miguel Gómez Cofrades committed Dec 5, 2023
1 parent 42470c8 commit f51d92d
Show file tree
Hide file tree
Showing 3 changed files with 2,236 additions and 2,178 deletions.
39 changes: 38 additions & 1 deletion docs/user-guide/advanced/Pandas_API.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2835,6 +2835,43 @@
"tab.prod(numeric_only=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Table.skew()\n",
"\n",
"```\n",
"Table.skew(axis=0, skipna=True, numeric_only=False)\n",
"```\n",
"\n",
"Returns the skewness of all values across the given axis.\n",
"\n",
"**Parameters:**\n",
"\n",
"| Name | Type | Description | Default |\n",
"| :----------: | :--: | :------------------------------------------------------------------------------- | :-----: |\n",
"| axis | int | The axis to calculate the product across 0 is columns, 1 is rows. | 0 |\n",
"| skipna | bool | Ignore any null values along the axis. | True |\n",
"| numeric_only | bool | Only use columns of the table that are of a numeric data type. | False |\n",
"\n",
"\n",
"**Returns:**\n",
"\n",
"| Type | Description |\n",
"| :----------------: | :------------------------------------------------------------------- |\n",
"| Dictionary | A dictionary where the key represent the column name / row number and the values are the result of calling `skew` on that column / row. |"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tab.skew(numeric_only=True)"
]
},
{
"cell_type": "markdown",
"id": "655c3ad2",
Expand Down Expand Up @@ -3317,7 +3354,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
11 changes: 11 additions & 0 deletions src/pykx/pandas_api/pandas_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@ def prod(self, axis=0, skipna=True, numeric_only=False, min_count=0):
min_count
), cols)

@convert_result
def skew(self, axis=0, skipna=True, numeric_only=False):
res, cols = preparse_computations(self, axis, skipna, numeric_only)
return (q(
'{[row]'
'm:{(sum(y-avg y)xexp x)%count y};'
'u:{sqrt[n*n-1]%neg[2]+n:count x};'
'{[u;m;x](u[x]*m[3][x]%(m[2][x]xexp 3%2))}[u;m]each row}',
res
), cols)

@convert_result
def sum(self, axis=0, skipna=True, numeric_only=False, min_count=0):
res, cols = preparse_computations(self, axis, skipna, numeric_only)
Expand Down
Loading

0 comments on commit f51d92d

Please sign in to comment.