Skip to content

Commit a28061e

Browse files
Simplify test and check for empty dataframe before truncating
This avoid type errors when the index is not initialized to timestamp
1 parent b724a52 commit a28061e

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

fourinsight/engineroom/utils/_core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ def truncate(self, before=None, after=None):
536536
after : int or datetime-like, optional
537537
Delete results with index greater than this value.
538538
"""
539+
if self._dataframe.empty == True:
540+
return
539541
index_drop = []
540542
if before:
541543
index_drop.extend(self._dataframe.index[(self._dataframe.index < before)])

tests/test_core.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -952,12 +952,8 @@ def test_when_noe_rows_delete_rows_truncate_timestamp(self):
952952
results = ResultCollector(headers, indexing_mode="timestamp")
953953
results.truncate(before="2020-01-01 01:00", after="2020-01-01 03:00")
954954
df_out = results.dataframe
955-
df_expect = pd.DataFrame(
956-
data={"a": [], "b": [], "c": [], "d": []},
957-
index=pd.RangeIndex(start=0, stop=0, step=1),
958-
).astype({"a": "float", "b": "string", "c": "Int64", "d": "float"})
959955

960-
pd.testing.assert_frame_equal(df_out, df_expect)
956+
assert df_out.empty
961957

962958
def test_delete_rows_truncate_timestamp(self):
963959
headers = {"a": float, "b": str, "c": int, "d": float}

0 commit comments

Comments
 (0)