Skip to content

Commit 6218233

Browse files
committed
Added code to handle case where dataframe created by to_dataframe is empty due to empty StreamSet(s)?
1 parent ff0824c commit 6218233

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

btrdb/transformers.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,15 @@ def to_dataframe(streamset, columns=None, agg="mean", name_callable=None):
145145

146146

147147
df = pd.DataFrame(to_dict(streamset,agg=agg))
148-
df = df.set_index("time")
149148

150-
if agg == "all" and not streamset.allow_window:
151-
stream_names = [[s.collection, s.name, prop] for s in streamset._streams for prop in _STAT_PROPERTIES]
152-
df.columns=pd.MultiIndex.from_tuples(stream_names)
153-
else:
154-
df.columns = columns if columns else _stream_names(streamset, name_callable)
149+
if not df.empty:
150+
df = df.set_index("time")
151+
152+
if agg == "all" and not streamset.allow_window:
153+
stream_names = [[s.collection, s.name, prop] for s in streamset._streams for prop in _STAT_PROPERTIES]
154+
df.columns=pd.MultiIndex.from_tuples(stream_names)
155+
else:
156+
df.columns = columns if columns else _stream_names(streamset, name_callable)
155157

156158
return df
157159

0 commit comments

Comments
 (0)