Skip to content

Commit

Permalink
Exposed the Series.values attribute
Browse files Browse the repository at this point in the history
This enables much more efficient processing of query results via the
public API by avoiding generators and unnecessary creation of KeyedTuple
objects.
  • Loading branch information
agronholm committed Sep 20, 2017
1 parent 75e2072 commit 5f6a657
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion asphalt/influxdb/client.py
Expand Up @@ -234,7 +234,7 @@ def get_series(result: Dict[str, Any]) -> Union[Series, List[Series], None]:
for series_dict in result['series']:
partial = series_dict.pop('partial', False)
if last_is_partial:
series_list[-1].add_values(series_dict['values'])
series_list[-1].values.extend(series_dict['values'])
else:
series = Series(**series_dict)
series_list.append(series)
Expand Down
14 changes: 7 additions & 7 deletions asphalt/influxdb/query.py
Expand Up @@ -70,25 +70,25 @@ class Series:
:ivar str name: name of the series
:ivar tuple columns: column names
:ivar values: result rows as a list of lists where the inner list elements correspond to
column names in the ``columns`` attribute
:type values: List[List]]
"""

__slots__ = ('name', 'columns', '_values')
__slots__ = ('name', 'columns', 'values')

def __init__(self, name: str, columns: List[str], values: List[list]) -> None:
self.name = name
self.columns = tuple(columns)
self._values = values

def add_values(self, values: List) -> None:
self._values.extend(values)
self.values = values

def __iter__(self):
columns = {key: index for index, key in enumerate(self.columns)}
for item in self._values:
for item in self.values:
yield KeyedTuple(columns, item)

def __len__(self):
return len(self._values)
return len(self.values)


class SelectQuery:
Expand Down
4 changes: 4 additions & 0 deletions docs/versionhistory.rst
Expand Up @@ -3,6 +3,10 @@ Version history

This library adheres to `Semantic Versioning <http://semver.org/>`_.

**2.1.0** (2017-09-20)

- Exposed the ``Series.values`` attribute to enable faster processing of query results

**2.0.1** (2017-06-04)

- Added compatibility with Asphalt 4.0
Expand Down

0 comments on commit 5f6a657

Please sign in to comment.