Skip to content

Commit ae1019f

Browse files
authored
Fixing unit test code (#49)
1 parent 305f164 commit ae1019f

File tree

5 files changed

+12
-182
lines changed

5 files changed

+12
-182
lines changed

.circleci/config.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,16 @@ commands:
5050
- run:
5151
name: install tox dependencies
5252
command: |
53-
pip install --user --upgrade pip virtualenv
53+
sudo pip uninstall -y poetry virtualenv
54+
pip install --user --upgrade pip virtualenv poetry
5455
pip install --user --quiet -r .circleci/circle_requirements.txt
5556
5657
- run:
5758
name: build sdist and wheels
5859
command: |
5960
# https://github.com/python-poetry/poetry/issues/4210
6061
poetry config experimental.new-installer false
62+
poetry config virtualenvs.create false
6163
poetry build
6264
6365
- run:
@@ -83,7 +85,7 @@ jobs:
8385
default: "latest"
8486
docker:
8587
- image: circleci/python:<<parameters.python_version>>
86-
- image: redislabs/rebloom:edge
88+
- image: redislabs/redismod:edge
8789
steps:
8890
- build_and_test
8991

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "redisbloom"
3-
version = "0.4.2"
3+
version = "0.5.0"
44
description = "RedisBloom Python Client"
55
authors = ["Redis <[email protected]>"]
66
license = "BSD-3-Clause"

redisbloom/__init__.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
from warnings import warn
2-
warn("Please upgrade to redis-py (https://pypi.org/project/redis/) "
3-
"This library is deprecated, and all features have been merged into redis-py.",
4-
DeprecationWarning, stacklevel=2)
2+
3+
warn(
4+
"Please upgrade to redis-py (https://pypi.org/project/redis/) "
5+
"This library is deprecated, and all features have been merged into redis-py.",
6+
DeprecationWarning,
7+
stacklevel=2,
8+
)

redisbloom/client.py

-117
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,6 @@ def __init__(self, args):
7171
self.decay = response['decay']
7272

7373

74-
class TDigestInfo(object):
75-
compression = None
76-
capacity = None
77-
mergedNodes = None
78-
unmergedNodes = None
79-
mergedWeight = None
80-
unmergedWeight = None
81-
totalCompressions = None
82-
83-
def __init__(self, args):
84-
response = dict(zip(map(nativestr, args[::2]), args[1::2]))
85-
self.compression = response['Compression']
86-
self.capacity = response['Capacity']
87-
self.mergedNodes = response['Merged nodes']
88-
self.unmergedNodes = response['Unmerged nodes']
89-
self.mergedWeight = response['Merged weight']
90-
self.unmergedWeight = response['Unmerged weight']
91-
self.totalCompressions = response['Total compressions']
92-
93-
9474
def spaceHolder(response):
9575
return response
9676

@@ -118,7 +98,6 @@ class Client(Redis): # changed from StrictRedis
11898
- CF for Cuckoo Filter
11999
- CMS for Count-Min Sketch
120100
- TOPK for TopK Data Structure
121-
- TDIGEST for estimate rank statistics
122101
"""
123102

124103
BF_RESERVE = 'BF.RESERVE'
@@ -157,16 +136,6 @@ class Client(Redis): # changed from StrictRedis
157136
TOPK_LIST = 'TOPK.LIST'
158137
TOPK_INFO = 'TOPK.INFO'
159138

160-
TDIGEST_CREATE = 'TDIGEST.CREATE'
161-
TDIGEST_RESET = 'TDIGEST.RESET'
162-
TDIGEST_ADD = 'TDIGEST.ADD'
163-
TDIGEST_MERGE = 'TDIGEST.MERGE'
164-
TDIGEST_CDF = 'TDIGEST.CDF'
165-
TDIGEST_QUANTILE = 'TDIGEST.QUANTILE'
166-
TDIGEST_MIN = 'TDIGEST.MIN'
167-
TDIGEST_MAX = 'TDIGEST.MAX'
168-
TDIGEST_INFO = 'TDIGEST.INFO'
169-
170139
def __init__(self, *args, **kwargs):
171140
"""
172141
Creates a new RedisBloom client.
@@ -212,15 +181,6 @@ def __init__(self, *args, **kwargs):
212181
self.TOPK_LIST: parseToList,
213182
self.TOPK_INFO: TopKInfo,
214183

215-
self.TDIGEST_CREATE: bool_ok,
216-
# self.TDIGEST_RESET: bool_ok,
217-
# self.TDIGEST_ADD: spaceHolder,
218-
# self.TDIGEST_MERGE: spaceHolder,
219-
# self.TDIGEST_CDF: spaceHolder,
220-
# self.TDIGEST_QUANTILE: spaceHolder,
221-
# self.TDIGEST_MIN: spaceHolder,
222-
# self.TDIGEST_MAX: spaceHolder,
223-
self.TDIGEST_INFO: TDigestInfo,
224184
}
225185
for k, v in six.iteritems(MODULE_CALLBACKS):
226186
self.set_response_callback(k, v)
@@ -613,83 +573,6 @@ def topkInfo(self, key):
613573

614574
return self.execute_command(self.TOPK_INFO, key)
615575

616-
################## T-Digest Functions ######################
617-
618-
def tdigestCreate(self, key, compression):
619-
""""
620-
Allocate the memory and initialize the t-digest.
621-
"""
622-
params = [key, compression]
623-
624-
return self.execute_command(self.TDIGEST_CREATE, *params)
625-
626-
def tdigestReset(self, key):
627-
"""
628-
Reset the sketch ``key`` to zero - empty out the sketch and re-initialize it.
629-
"""
630-
631-
return self.execute_command(self.TDIGEST_RESET, key)
632-
633-
def tdigestAdd(self, key, values, weights):
634-
"""
635-
Adds one or more samples (value with weight) to a sketch ``key``.
636-
Both ``values`` and ``weights`` are lists.
637-
Example - tdigestAdd('A', [1500.0], [1.0])
638-
"""
639-
params = [key]
640-
self.appendValuesAndWeights(params, values, weights)
641-
642-
return self.execute_command(self.TDIGEST_ADD, *params)
643-
644-
def tdigestMerge(self, toKey, fromKey):
645-
"""
646-
Merges all of the values from 'fromKey' to 'toKey' sketch.
647-
"""
648-
params = [toKey, fromKey]
649-
650-
return self.execute_command(self.TDIGEST_MERGE, *params)
651-
652-
def tdigestMin(self, key):
653-
"""
654-
Returns minimum value from the sketch ``key``.
655-
Will return DBL_MAX if the sketch is empty.
656-
"""
657-
658-
return self.execute_command(self.TDIGEST_MIN, key)
659-
660-
def tdigestMax(self, key):
661-
"""
662-
Returns maximum value from the sketch ``key``.
663-
Will return DBL_MIN if the sketch is empty.
664-
"""
665-
666-
return self.execute_command(self.TDIGEST_MAX, key)
667-
668-
def tdigestQuantile(self, key, quantile):
669-
"""
670-
Returns double value estimate of the cutoff such that a specified fraction of the data added
671-
to this TDigest would be less than or equal to the cutoff.
672-
"""
673-
params = [key, quantile]
674-
675-
return self.execute_command(self.TDIGEST_QUANTILE, *params)
676-
677-
def tdigestCdf(self, key, value):
678-
"""
679-
Returns double fraction of all points added which are <= value.
680-
"""
681-
params = [key, value]
682-
683-
return self.execute_command(self.TDIGEST_CDF, *params)
684-
685-
def tdigestInfo(self, key):
686-
"""
687-
Returns Compression, Capacity, Merged Nodes, Unmerged Nodes, Merged Weight, Unmerged Weight
688-
and Total Compressions.
689-
"""
690-
691-
return self.execute_command(self.TDIGEST_INFO, key)
692-
693576
def pipeline(self, transaction=True, shard_hint=None):
694577
"""
695578
Return a new pipeline object that can queue multiple commands for

test_commands.py

-59
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def testCreate(self):
3434
self.assertTrue(rb.cmsInitByDim('cmsDim', 100, 5))
3535
self.assertTrue(rb.cmsInitByProb('cmsProb', 0.01, 0.01))
3636
self.assertTrue(rb.topkReserve('topk', 5, 100, 5, 0.9))
37-
self.assertTrue(rb.tdigestCreate('tDigest', 100))
3837

3938
################### Test Bloom Filter ###################
4039
def testBFAdd(self):
@@ -208,64 +207,6 @@ def testTopK(self):
208207
self.assertEqual(3, info.depth)
209208
self.assertAlmostEqual(0.9, float(info.decay))
210209

211-
################### Test T-Digest ###################
212-
def testTDigestReset(self):
213-
self.assertTrue(rb.tdigestCreate('tDigest', 10))
214-
# reset on empty histogram
215-
self.assertTrue(rb.tdigestReset('tDigest'))
216-
# insert data-points into sketch
217-
self.assertTrue(rb.tdigestAdd('tDigest', list(range(10)), [1.0] * 10))
218-
219-
self.assertTrue(rb.tdigestReset('tDigest'))
220-
# assert we have 0 unmerged nodes
221-
self.assertEqual(0, rb.tdigestInfo('tDigest').unmergedNodes)
222-
223-
def testTDigestMerge(self):
224-
self.assertTrue(rb.tdigestCreate('to-tDigest', 10))
225-
self.assertTrue(rb.tdigestCreate('from-tDigest', 10))
226-
# insert data-points into sketch
227-
self.assertTrue(rb.tdigestAdd('from-tDigest', [1.0] * 10, [1.0] * 10))
228-
self.assertTrue(rb.tdigestAdd('to-tDigest', [2.0] * 10, [10.0] * 10))
229-
# merge from-tdigest into to-tdigest
230-
self.assertTrue(rb.tdigestMerge('to-tDigest', 'from-tDigest'))
231-
# we should now have 110 weight on to-histogram
232-
info = rb.tdigestInfo('to-tDigest')
233-
total_weight_to = float(info.mergedWeight) + float(info.unmergedWeight)
234-
self.assertEqual(110, total_weight_to)
235-
236-
def testTDigestMinMax(self):
237-
self.assertTrue(rb.tdigestCreate('tDigest', 100))
238-
# insert data-points into sketch
239-
self.assertTrue(rb.tdigestAdd('tDigest', [1, 2, 3], [1.0] * 3))
240-
# min/max
241-
self.assertEqual(3, float(rb.tdigestMax('tDigest')))
242-
self.assertEqual(1, float(rb.tdigestMin('tDigest')))
243-
244-
def testTDigestQuantile(self):
245-
self.assertTrue(rb.tdigestCreate('tDigest', 500))
246-
# insert data-points into sketch
247-
self.assertTrue(rb.tdigestAdd('tDigest', list([x * 0.01 for x in range(1, 10000)]), [1.0] * 10000))
248-
# assert min min/max have same result as quantile 0 and 1
249-
self.assertEqual(
250-
float(rb.tdigestMax('tDigest')),
251-
float(rb.tdigestQuantile('tDigest', 1.0)),
252-
)
253-
self.assertEqual(
254-
float(rb.tdigestMin('tDigest')),
255-
float(rb.tdigestQuantile('tDigest', 0.0)),
256-
)
257-
258-
self.assertAlmostEqual(1.0, float(rb.tdigestQuantile('tDigest', 0.01)), 2)
259-
self.assertAlmostEqual(99.0, float(rb.tdigestQuantile('tDigest', 0.99)), 2)
260-
261-
def testTDigestCdf(self):
262-
self.assertTrue(rb.tdigestCreate('tDigest', 100))
263-
# insert data-points into sketch
264-
self.assertTrue(rb.tdigestAdd('tDigest', list(range(1, 10)), [1.0] * 10))
265-
266-
self.assertAlmostEqual(0.1, float(rb.tdigestCdf('tDigest', 1.0)), 1)
267-
self.assertAlmostEqual(0.9, float(rb.tdigestCdf('tDigest', 9.0)), 1)
268-
269210
def test_pipeline(self):
270211
pipeline = rb.pipeline()
271212

0 commit comments

Comments
 (0)