10000 feat: add __repr__ methods for FluxTable, FluxColumn, FluxRecord (#281) · calvinlua/influxdb-client-python@2a0bd82 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2a0bd82

Browse files
authored
feat: add __repr__ methods for FluxTable, FluxColumn, FluxRecord (influxdata#281)
1 parent 2ac071d commit 2a0bd82

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## 1.20.0 [unreleased]
22

3+
### Features
4+
1. [#281](https://github.com/influxdata/influxdb-client-python/pull/281): `FluxTable`, `FluxColumn` and `FluxRecord` objects have helpful reprs
5+
36
## 1.19.0 [2021-07-09]
47

58
### Features

influxdb_client/client/flux_table.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ def __str__(self):
3232
cls_name = type(self).__name__
3333
return cls_name + "() columns: " + str(len(self.columns)) + ", records: " + str(len(self.records))
3434

35+
def __repr__(self):
36+
"""Format for inspection."""
37+
return f"<{type(self).__name__}: {len(self.columns)} columns, {len(self.records)} records>"
38+
3539
def __iter__(self):
3640
"""Iterate over records."""
3741
return iter(self.records)
@@ -48,6 +52,15 @@ def __init__(self, index=None, label=None, data_type=None, group=None, default_v
4852
self.label = label
4953
self.index = index
5054

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

5265
class FluxRecord(FluxStructure):
5366
"""A record is a tuple of named values and is represented using an object type."""
@@ -95,3 +108,7 @@ def __str__(self):
95108
"""Return formatted output."""
96109
cls_name = type(self).__name__
97110
return cls_name + "() table: " + str(self.table) + ", " + str(self.values)
111+
112+
def __repr__(self):
113+
"""Format for inspection."""
114+
return f"<{type(self).__name__}: field={self.values.get('_field')}, value={self.values.get('_value')}>"

0 commit comments

Comments
 (0)
0