Skip to content

Commit

Permalink
feat: add __repr__ methods for FluxTable, FluxColumn, FluxRecord (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver authored Jul 9, 2021
1 parent 2ac071d commit 2a0bd82
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 1.20.0 [unreleased]

### Features
1. [#281](https://github.com/influxdata/influxdb-client-python/pull/281): `FluxTable`, `FluxColumn` and `FluxRecord` objects have helpful reprs

## 1.19.0 [2021-07-09]

### Features
Expand Down
17 changes: 17 additions & 0 deletions influxdb_client/client/flux_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def __str__(self):
cls_name = type(self).__name__
return cls_name + "() columns: " + str(len(self.columns)) + ", records: " + str(len(self.records))

def __repr__(self):
"""Format for inspection."""
return f"<{type(self).__name__}: {len(self.columns)} columns, {len(self.records)} records>"

def __iter__(self):
"""Iterate over records."""
return iter(self.records)
Expand All @@ -48,6 +52,15 @@ def __init__(self, index=None, label=None, data_type=None, group=None, default_v
self.label = label
self.index = index

def __repr__(self):
"""Format for inspection."""
fields = [repr(self.index)] + [
f'{name}={getattr(self, name)!r}' for name in (
'label', 'data_type', 'group', 'default_value'
) if getattr(self, name) is not None
]
return f"{type(self).__name__}({', '.join(fields)})"


class FluxRecord(FluxStructure):
"""A record is a tuple of named values and is represented using an object type."""
Expand Down Expand Up @@ -95,3 +108,7 @@ def __str__(self):
"""Return formatted output."""
cls_name = type(self).__name__
return cls_name + "() table: " + str(self.table) + ", " + str(self.values)

def __repr__(self):
"""Format for inspection."""
return f"<{type(self).__name__}: field={self.values.get('_field')}, value={self.values.get('_value')}>"

0 comments on commit 2a0bd82

Please sign in to comment.