Skip to content

Commit ce19e59

Browse files
committed
insert: move more sanity checks to _guard
This is useful for specialized inserters.
1 parent 94bc86e commit ce19e59

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

tshistory/tsio.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,10 @@ def insert(self, cn, newts, name, author,
5555
author: str free-form author name
5656
metadata: optional dict for changeset metadata
5757
"""
58-
assert isinstance(name, str), 'Name not a string'
59-
assert isinstance(author, str), 'Author not a string'
60-
assert metadata is None or isinstance(metadata, dict), 'Bad format for metadata'
61-
assert (_insertion_date is None or
62-
isinstance(_insertion_date, datetime)), 'Bad format for insertion date'
63-
newts = self._guard_insert(newts)
58+
newts = self._guard_insert(
59+
newts, name, author, metadata,
60+
_insertion_date
61+
)
6462
if not len(newts):
6563
return
6664

@@ -434,7 +432,12 @@ def interval(self, cn, name, notz=False):
434432

435433
# creation / update
436434

437-
def _guard_insert(self, newts):
435+
def _guard_insert(self, newts, name, author, metadata, insertion_date):
436+
assert isinstance(name, str), 'Name not a string'
437+
assert isinstance(author, str), 'Author not a string'
438+
assert metadata is None or isinstance(metadata, dict), 'Bad format for metadata'
439+
assert (insertion_date is None or
440+
isinstance(insertion_date, datetime)), 'Bad format for insertion date'
438441
assert isinstance(newts, pd.Series), 'Not a pd.Series'
439442
assert not newts.index.duplicated().any(), 'There are some duplicates in the index'
440443

0 commit comments

Comments
 (0)