1
0
mirror of https://github.com/balkian/tsih.git synced 2025-09-16 01:52:23 +00:00

Compare commits

4 Commits

Author SHA1 Message Date
J. Fernando Sánchez
eaddd89e8c minor bug fixes 2023-03-23 14:18:32 +01:00
J. Fernando Sánchez
4e0e95fbe7 remove pandas deprecation warnings 2023-03-23 12:16:42 +01:00
J. Fernando Sánchez
92c5c219bd Remove unnecessary exception flush_cache on readonly dbs 2022-03-08 09:51:45 +01:00
J. Fernando Sánchez
c857890d91 Add NoHistory 2021-10-15 20:18:20 +02:00

View File

@@ -10,7 +10,7 @@ import tempfile
logger = logging.getLogger(__name__)
__version__ = '0.1.4'
__version__ = '0.1.9'
from collections import UserDict, namedtuple
@@ -138,7 +138,7 @@ class History:
self._close()
def _close(self):
if self._db is None:
if not hasattr(self, '_db') or self._db is None:
return
self.flush_cache()
self._db.close()
@@ -240,7 +240,7 @@ class History:
The cache will be flushed at the end of the simulation, and when history is accessed.
'''
if self.readonly:
raise Exception('DB in readonly mode')
return
logger.debug('Flushing cache {}'.format(self.db_path))
with self.db:
self.db.executemany("replace into history(dict_id, t_step, key, value) values (?, ?, ?, ?)", self._tups)
@@ -400,9 +400,9 @@ class Records():
return sum(1 for i in self._filter if i is not None) == 3
def __iter__(self):
for column, series in self._df.iteritems():
for column, series in self._df.items():
key, dict_id = column
for t_step, value in series.iteritems():
for t_step, value in series.items():
r = Record(t_step=t_step,
dict_id=dict_id,
key=key,
@@ -414,7 +414,7 @@ class Records():
f = self._filter
try:
i = self._df[f.key][str(f.dict_id)]
ix = i.index.get_loc(f.t_step, method='ffill')
ix = i.index.get_indexer([f.t_step], method='ffill')[0]
return i.iloc[ix]
except KeyError as ex:
return self.dtypes[f.key][2]()
@@ -442,3 +442,43 @@ Key = namedtuple('Key', ['dict_id', 't_step', 'key'])
Record = namedtuple('Record', 'dict_id t_step key value')
Stat = namedtuple('Stat', 'stat_id text')
class NoHistory:
'''Empty implementation for history meant for testing.'''
def __init__(self, *args, **kwargs):
pass
def close(self):
pass
def save_stats(self, stat):
pass
def get_stats(self, unflatten=True):
return []
def save_tuples(self, tuples):
return
def save_records(self, records):
return
def save_record(self, dict_id, t_step, key, value):
return
def flush_cache(self):
return
def to_tuples(self):
return []
def __getitem__(self, key):
return None
def read_sql(self, keys=None, dict_ids=None, not_dict_ids=None, t_steps=None, convert_types=False, limit=-1):
return pandas.Dataframe()
def dump(self, f):
return