Skip to content

Commit

Permalink
Merge pull request #28 from nooperpudd/feature/upgrade_version
Browse files Browse the repository at this point in the history
upgrade python package version and fix the test assert.
  • Loading branch information
nooperpudd authored Sep 3, 2020
2 parents 64dc64d + 6651a3e commit 3c9daa3
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 98 deletions.
4 changes: 4 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ environment:
PYTHON_VERSION: "3.7"
PYTHON_ARCH: "64"

- PYTHON: "C:\\Python38-x64"
PYTHON_VERSION: "3.8"
PYTHON_ARCH: "64"

init:
# If there is a newer build queued for the same PR, cancel this one.
# The AppVeyor 'rollout builds' option is supposed to serve the same
Expand Down
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ matrix:
- python: 3.7
sudo: required
dist: xenial
- python: 3.8
sudo: required

services:
- redis-server
- redis

compiler:
- clang
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ High performance engine to store Time series data in Redis.

|travis| |appveyor| |codecov| |codacy| |requirements| |docs| |pypi| |status| |pyversion| |download|

Redis Version required: >=5.0

TT-series is based on redis sorted sets to store the time-series data, `Sorted set`_ store scores with
unique numbers under a single key, but it has a weakness to store records, only unique members are allowed
Expand Down
151 changes: 83 additions & 68 deletions benchmark/report.txt

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

; To send tests to multiple CPUs
;addopts = -n2 -v --boxed
# todo support multi tests
addopts = -v

testpaths = tests
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
msgpack>=0.6.1
numpy>=1.16.0
python-dateutil>=2.7.5
redis>=3.0.0
hiredis>=1.0.0
pandas>=0.24.0
msgpack>=1.0.0
numpy>=1.19.1
python-dateutil>=2.8.1
redis>=3.5.3
hiredis>=1.1.0
pandas>=1.1.1
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def find_version(*file_paths):
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries"
],
Expand Down
20 changes: 7 additions & 13 deletions tests/test_pandas_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ def test_add(self):

series_item = data_frame.iloc[0]


self.time_series.add(key, series_item)

datetime_value = data_frame.index.to_pydatetime()[0]

timestamp = datetime_value.timestamp()


result = self.time_series.get(key, timestamp)

pandas.testing.assert_series_equal(series_item, result)
Expand All @@ -35,20 +33,18 @@ def test_get_slice(self):
self.time_series.add_many(key, data_frame)

results_frame = self.time_series.get_slice(key)


pandas.testing.assert_frame_equal(results_frame,data_frame)
self.assertTrue(data_frame.equals(results_frame))

def test_iter(self):
key = "AAPL:SECOND"
data_frame = self.prepare_dataframe(10)
self.time_series.add_many(key, data_frame)
new_data_frame = self.dataframe_empty(self.columns,
dtypes=self.dtypes)
new_data_frame = self.dataframe_empty(self.columns, dtypes=self.dtypes)

for series in self.time_series.iter(key):
new_data_frame = new_data_frame.append(series)
pandas.testing.assert_frame_equal(data_frame, new_data_frame)

self.assertTrue(data_frame.equals(new_data_frame))

def test_add_exists_timestamp_assert_error(self):
key = "AAPL:SECOND"
Expand All @@ -66,7 +62,7 @@ def test_add_many_trim_data(self):
self.time_series.add_many(key, data_frame2)
results_frame = self.time_series.get_slice(key)

pandas.testing.assert_frame_equal(results_frame, data_frame2.iloc[10:])
self.assertTrue(results_frame.equals(data_frame2.iloc[10:]))


class RedisPandasTimeSeriesTest(unittest.TestCase, RedisPandasMixin):
Expand Down Expand Up @@ -96,13 +92,11 @@ def prepare_dataframe(self, length, time_span=None):

date_range = pandas.date_range(now, periods=length, freq="1min")

data_frame = pandas.DataFrame([i + 1 for i in range(len(date_range))],
index=date_range, columns=self.columns)
data_frame = pandas.DataFrame([i + 1 for i in range(len(date_range))],
index=date_range, columns=self.columns)
data_frame.index.name = self.index_name
return data_frame



def dataframe_empty(self, columns, dtypes, index=None):
data_frame = pandas.DataFrame(index=index)
for column in columns:
Expand Down
2 changes: 1 addition & 1 deletion ttseries/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
from .ts import RedisPandasTimeSeries
from .serializers import BaseSerializer

__version__ = "0.2.1"
__version__ = "0.2.2"
1 change: 0 additions & 1 deletion ttseries/ts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def __init__(self, redis_client, max_length=100000, transaction=True,
raise SerializerError("Serializer class must inherit from "
"ttseries.serializers.BaseSerializer abstract class")


@property
@functools.lru_cache(maxsize=4096)
def client(self):
Expand Down
6 changes: 3 additions & 3 deletions ttseries/ts/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def add(self, name: str, timestamp: float, data) -> bool:

def pipe_func(_pipe): # trans function
_pipe.zadd(name, {key_id: timestamp})
_pipe.hmset(hash_key, dumps_dict) # APPL:second:HASH, {1:value}
_pipe.hset(hash_key, mapping=dumps_dict) # APPL:second:HASH, {1:value}

watch_keys = (name, hash_key) # APPL:SECOND , APPL:second:HASH
return self.transaction_pipe(pipe_func, watch_keys)
Expand Down Expand Up @@ -236,7 +236,7 @@ def add_many(self, name, array: list, chunks_size=2000):

def pipe_func(_pipe):
_pipe.zadd(name, timestamp_ids)
_pipe.hmset(hash_key, ids_values)
_pipe.hset(hash_key, mapping=ids_values)

self.transaction_pipe(pipe_func, watch_keys=(name, hash_key))

Expand All @@ -260,4 +260,4 @@ def iter(self, name):

for timestamp_pairs, hash_pairs in itertools.zip_longest(self.client.zscan_iter(name=name),
self.client.hscan_iter(name=hash_key)):
yield (timestamp_pairs[1], self._serializer.loads(hash_pairs[1]))
yield timestamp_pairs[1], self._serializer.loads(hash_pairs[1])
3 changes: 1 addition & 2 deletions ttseries/ts/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ def add(self, name, series):
values = series.tolist()
data = self._serializer.dumps(values)
if self.length(name) == self.max_length:
# todo use 5.0 BZPOPMIN
self.client.zremrangebyrank(name, min=0, max=0)
self.client.zpopmin(name)
return self.client.zadd(name, {data: timestamp})
else:
raise RedisTimeSeriesError("Please check series Type or "
Expand Down
3 changes: 1 addition & 2 deletions ttseries/ts/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def add(self, name: str, timestamp: float, data):
if not self.exist_timestamp(name, timestamp):
data = self._serializer.dumps(data)
if self.length(name) == self.max_length:
# todo use 5.0 BZPOPMIN
self.client.zremrangebyrank(name, min=0, max=0)
self.client.zpopmin(name)

return self.client.zadd(name, mapping={data: timestamp})

Expand Down

0 comments on commit 3c9daa3

Please sign in to comment.