From f531e0aab83e4ab9c9da6cc634922b0c180ded84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Thu, 24 Jun 2021 16:52:48 +0200 Subject: [PATCH] more class constructors use explicit typing - faster tempsdb --- README.md | 3 ++- setup.cfg | 2 +- tempsdb/chunks/base.pyx | 4 ++-- tempsdb/chunks/direct.pyx | 4 ++-- tempsdb/chunks/gzip.pyx | 2 +- tempsdb/database.pyx | 4 ++-- tempsdb/iterators.pyx | 2 +- tempsdb/series.pyx | 2 +- tempsdb/varlen.pyx | 2 +- 9 files changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4434735..22cf48a 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,8 @@ Then copy your resulting wheel and install it via pip on the target system. * fixed minor compiler warnings * `TimeSeries.iterate_range` will accept a parameter called `direct_bytes` for compatibility with `VarlenSeries`. - It's value is ignored. + It's value is ignored +* more class constructors use explicit typing - faster tempsdb ## v0.5.4 diff --git a/setup.cfg b/setup.cfg index 6266526..826a120 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ # coding: utf-8 [metadata] name = tempsdb -version = 0.6a3 +version = 0.6a4 long-description = file: README.md long-description-content-type = text/markdown; charset=UTF-8 license_files = LICENSE diff --git a/tempsdb/chunks/base.pyx b/tempsdb/chunks/base.pyx index 222f7b0..344b725 100644 --- a/tempsdb/chunks/base.pyx +++ b/tempsdb/chunks/base.pyx @@ -171,8 +171,8 @@ cdef class Chunk: cpdef object open_file(self, str path): return open(self.path, 'rb+') - def __init__(self, parent: tp.Optional[TimeSeries], path: str, page_size: int, - use_descriptor_access: bool = False): + def __init__(self, TimeSeries parent, str path, int page_size, + bint use_descriptor_access = False): cdef bytes b self.file_size = os.path.getsize(path) self.page_size = page_size diff --git a/tempsdb/chunks/direct.pyx b/tempsdb/chunks/direct.pyx index af811cf..2664928 100644 --- a/tempsdb/chunks/direct.pyx +++ b/tempsdb/chunks/direct.pyx @@ -30,9 +30,9 @@ cdef class DirectChunk(Chunk): gzip disabled. If given, a warning will be emitted as gzip support is still experimental. :raises ValueError: non-direct descriptor was requested and gzip was enabled """ - def __init__(self, parent: tp.Optional[TimeSeries], path: str, page_size: int, + def __init__(self, TimeSeries parent, str path, int page_size, use_descriptor_access: tp.Optional[bool] = None, - gzip_compression_level: int = 0): + int gzip_compression_level = 0): if path.endswith('.gz'): warnings.warn('Please pass the path without .gz') path = path.replace('.gz', '') diff --git a/tempsdb/chunks/gzip.pyx b/tempsdb/chunks/gzip.pyx index 5531909..c76d10b 100644 --- a/tempsdb/chunks/gzip.pyx +++ b/tempsdb/chunks/gzip.pyx @@ -3,7 +3,7 @@ import threading cdef class ReadWriteGzipFile: - def __init__(self, path: str, compresslevel: int = gzip._COMPRESS_LEVEL_FAST): + def __init__(self, str path, int compresslevel = gzip._COMPRESS_LEVEL_FAST): self.path = path self.compress_level = compresslevel self.rw_file = gzip.GzipFile(path, 'ab', compresslevel=self.compress_level) diff --git a/tempsdb/database.pyx b/tempsdb/database.pyx index 97c0e94..ce885d8 100644 --- a/tempsdb/database.pyx +++ b/tempsdb/database.pyx @@ -25,7 +25,7 @@ cdef class Database: :ivar path: path to the directory with the database (str) :ivar metadata: metadata of this DB """ - def __init__(self, path: str): + def __init__(self, str path): if not os.path.isdir(path): raise DoesNotExist('Database does not exist') @@ -135,7 +135,7 @@ cdef class Database: shutil.rmtree(path) return 0 - cpdef TimeSeries get_series(self, name: str, bint use_descriptor_based_access = False): + cpdef TimeSeries get_series(self, str name, bint use_descriptor_based_access = False): """ Load and return an existing series diff --git a/tempsdb/iterators.pyx b/tempsdb/iterators.pyx index 28d5633..f0a0f4d 100644 --- a/tempsdb/iterators.pyx +++ b/tempsdb/iterators.pyx @@ -27,7 +27,7 @@ cdef class Iterator: :meth:`~tempsdb.iterators.Iterator.close`. """ - def __init__(self, parent: TimeSeries, start: int, stop: int, chunks: tp.List[Chunk]): + def __init__(self, TimeSeries parent, int start, int stop, list chunks): self.start = start self.stop = stop self.current_chunk = None diff --git a/tempsdb/series.pyx b/tempsdb/series.pyx index 3c60ab2..d04ad34 100644 --- a/tempsdb/series.pyx +++ b/tempsdb/series.pyx @@ -94,7 +94,7 @@ cdef class TimeSeries: chunk.switch_to_mmap_based_access() return 0 - def __init__(self, path: str, name: str, use_descriptor_based_access: bool = False): + def __init__(self, str path, str name, bint use_descriptor_based_access = False): self.descriptor_based_access = use_descriptor_based_access self.mpm = None self.name = name diff --git a/tempsdb/varlen.pyx b/tempsdb/varlen.pyx index e8efb8b..f17211b 100644 --- a/tempsdb/varlen.pyx +++ b/tempsdb/varlen.pyx @@ -486,7 +486,7 @@ cdef class VarlenSeries: et.close() it.close() - def __init__(self, path: str, name: str, use_descriptor_based_access: bool = False): + def __init__(self, str path, str name, bint use_descriptor_based_access = False): self.closed = False self.mmap_enabled = not use_descriptor_based_access self.path = path -- GitLab