Skip to content
Merged
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
1 change: 1 addition & 0 deletions redis/commands/bf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def __init__(self, client, **kwargs):
TDIGEST_QUANTILE: parse_tdigest_quantile,
TDIGEST_MIN: float,
TDIGEST_MAX: float,
TDIGEST_TRIMMED_MEAN: float,
TDIGEST_INFO: TDigestInfo,
}

Expand Down
11 changes: 11 additions & 0 deletions redis/commands/bf/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
TDIGEST_MIN = "TDIGEST.MIN"
TDIGEST_MAX = "TDIGEST.MAX"
TDIGEST_INFO = "TDIGEST.INFO"
TDIGEST_TRIMMED_MEAN = "TDIGEST.TRIMMED_MEAN"
TDIGEST_MERGESTORE = "TDIGEST.MERGESTORE"


Expand Down Expand Up @@ -418,6 +419,16 @@ def info(self, key):
""" # noqa
return self.execute_command(TDIGEST_INFO, key)

def trimmed_mean(self, key, low_cut_quantile, high_cut_quantile):
"""
Return mean value from the sketch, excluding observation values outside
the low and high cutoff quantiles.
For more information see `TDIGEST.TRIMMED_MEAN <https://redis.io/commands/tdigest.trimmed_mean>`_.
""" # noqa
return self.execute_command(
TDIGEST_TRIMMED_MEAN, key, low_cut_quantile, high_cut_quantile
)

def mergestore(self, dest_key, numkeys, *sourcekeys, compression=False):
"""
Merges all of the values from `sourcekeys` keys to `dest_key` sketch.
Expand Down
11 changes: 11 additions & 0 deletions tests/test_bloom.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,17 @@ def test_tdigest_cdf(client):
assert 0.9 == round(client.tdigest().cdf("tDigest", 9.0), 1)


@pytest.mark.redismod
@pytest.mark.experimental
@skip_ifmodversion_lt("2.4.0", "bf")
def test_tdigest_trimmed_mean(client):
assert client.tdigest().create("tDigest", 100)
# insert data-points into sketch
assert client.tdigest().add("tDigest", list(range(1, 10)), [1.0] * 10)
assert 5 == client.tdigest().trimmed_mean("tDigest", 0.1, 0.9)
assert 4.5 == client.tdigest().trimmed_mean("tDigest", 0.4, 0.5)


@pytest.mark.redismod
@pytest.mark.experimental
@skip_ifmodversion_lt("2.4.0", "bf")
Expand Down