Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

minor fix for quantile arg #348

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions torcharrow/icolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,14 +1457,17 @@ def _nunique(self, drop_null=True):
else:
return len(set(i for i in self if i is not None))

# quantile
@trace
@expression
def _quantile(self, q, interpolation="midpoint"):
"""
Compute the q-th percentile of non-null data.
Compute the q-th quantile of non-null data.

Inefficient prototype implementation.

Args:
q: float or array-like quantiles to compute, value must be within [0, 1]
interpolation: interpolation method to use
"""

if interpolation != "midpoint":
Expand All @@ -1475,8 +1478,8 @@ def _quantile(self, q, interpolation="midpoint"):
return []
out = []
s = sorted(self)
for percent in q:
k = (len(self) - 1) * (percent / 100)
for p in q:
k = (len(self) - 1) * p
f = math.floor(k)
c = math.ceil(k)
if f == c:
Expand Down
2 changes: 1 addition & 1 deletion torcharrow/inumerical_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def describe(
res._append(("mean", self.mean()))
res._append(("std", self.std()))
res._append(("min", self.min()))
values = self._quantile(percentiles, "midpoint")
values = self._quantile(percentiles / 100, "midpoint")
for p, v in zip(percentiles, values):
res._append((f"{p}%", v))
res._append(("max", self.max()))
Expand Down