Skip to content

Commit e7d8e54

Browse files
authored
Merge pull request #715 from ibm-watson-iot/kohlmann-master-groupkey
[patch] Make index available to aggregators
2 parents fe36592 + fb54dea commit e7d8e54

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

iotfunctions/aggregate.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,12 @@ def _agg_dict(self, df, simple_aggregators):
112112

113113
def execute(self, df, start_ts=None, end_ts=None, entities=None, offset=None):
114114

115-
# The index has been moved to the columns and the index levels ('id', event timestamp, dimensions) can now be
116-
# used as a starting point of an aggregation. Provide index level 'id' - if it exists - as 'entity_id' as well.
117-
if 'id' in df.columns:
118-
df['entity_id'] = df['id']
115+
# Make index of dataframe available as columns
116+
for index_name in df.index.names:
117+
if index_name == 'id':
118+
df['entity_id'] = df.index.get_level_values('id')
119+
else:
120+
df[index_name] = df.index.get_level_values(index_name)
119121

120122
# Gather columns which are used to determine the groups
121123
group_base = []

0 commit comments

Comments
 (0)