Skip to content

Commit

Permalink
Draft for skew implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jesus.lopez7.contractor committed Nov 8, 2023
1 parent 0fa1d5c commit 6c22159
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/pykx/pandas_api/pandas_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,6 @@ def any(self, axis=0, bool_only=False, skipna=True):
res, cols = preparse_computations(self, axis, skipna, bool_only=bool_only)
return (q('{"b"$x}', [any(x) for x in res]), cols)

@convert_result
def cumsum(self, axis=0, skipna=True):
res, cols = preparse_computations(self, axis, skipna)
return (q(
'{[row]'
'{$[11h=type x;'
'{[x1; y1] `$string[x1], string y1} scan x;'
'sums x]} each row}',
res
), cols)

@convert_result
def max(self, axis=0, skipna=True, numeric_only=False):
res, cols = preparse_computations(self, axis, skipna, numeric_only)
Expand All @@ -255,6 +244,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
10 changes: 10 additions & 0 deletions tests/test_pandas_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,16 @@ def test_pandas_sum(q):
for i in range(10):
assert qsum[i] == q('0N')
assert str(psum[i]) == 'nan'


def test_pandas_skew(q):
tab = q('([] price: 250.0f - 100?500.0f; ints: 100 - 100?200)')
df = tab.pd()

qskew = tab.skew().py()
pskew = df.skew()
assert round(float(qskew['price']), 6) == round(float(pskew['price']), 6)
assert round(float(qskew['ints']), 6) == round(float(pskew['ints']), 6)


def test_pandas_groupby_errors(kx, q):
Expand Down

0 comments on commit 6c22159

Please sign in to comment.