1
0
mirror of https://github.com/balkian/tsih.git synced 2025-09-19 03:22:22 +00:00

3 Commits
0.1.5 ... 0.1.9

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

View File

@@ -10,7 +10,7 @@ import tempfile
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
__version__ = '0.1.5' __version__ = '0.1.9'
from collections import UserDict, namedtuple from collections import UserDict, namedtuple
@@ -138,7 +138,7 @@ class History:
self._close() self._close()
def _close(self): def _close(self):
if self._db is None: if not hasattr(self, '_db') or self._db is None:
return return
self.flush_cache() self.flush_cache()
self._db.close() 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. The cache will be flushed at the end of the simulation, and when history is accessed.
''' '''
if self.readonly: if self.readonly:
raise Exception('DB in readonly mode') return
logger.debug('Flushing cache {}'.format(self.db_path)) logger.debug('Flushing cache {}'.format(self.db_path))
with self.db: with self.db:
self.db.executemany("replace into history(dict_id, t_step, key, value) values (?, ?, ?, ?)", self._tups) 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 return sum(1 for i in self._filter if i is not None) == 3
def __iter__(self): def __iter__(self):
for column, series in self._df.iteritems(): for column, series in self._df.items():
key, dict_id = column key, dict_id = column
for t_step, value in series.iteritems(): for t_step, value in series.items():
r = Record(t_step=t_step, r = Record(t_step=t_step,
dict_id=dict_id, dict_id=dict_id,
key=key, key=key,
@@ -414,7 +414,7 @@ class Records():
f = self._filter f = self._filter
try: try:
i = self._df[f.key][str(f.dict_id)] 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] return i.iloc[ix]
except KeyError as ex: except KeyError as ex:
return self.dtypes[f.key][2]() return self.dtypes[f.key][2]()