petl-developers / petl

Python Extract Transform and Load Tables of Data
MIT License
1.25k stars 193 forks source link

dicts attribute of DictsView conflicts with util.base.dicts() method #643

Open bmaggard opened 1 year ago

bmaggard commented 1 year ago

https://github.com/petl-developers/petl/blob/a8add27bcc607644a49ed11fcd64fcb26d8218f7/petl/io/json.py#L197

In [1]: import petl as etl

In [2]: dummy = etl.dummytable()

In [3]: dummy
Out[3]: 
+-----+-----------+---------------------+
| foo | bar       | baz                 |
+=====+===========+=====================+
|  24 | 'apples'  |  0.9829038224380889 |
+-----+-----------+---------------------+
|  44 | 'oranges' | 0.14938272048364054 |
+-----+-----------+---------------------+
|  54 | 'pears'   |  0.7060235672693753 |
+-----+-----------+---------------------+
|  58 | 'pears'   | 0.12677371544592353 |
+-----+-----------+---------------------+
|  17 | 'pears'   |  0.2684826823900752 |
+-----+-----------+---------------------+
...

In [4]: dummy.dicts()
Out[4]: 
{'foo': 24, 'bar': 'apples', 'baz': 0.9829038224380889}
{'foo': 44, 'bar': 'oranges', 'baz': 0.14938272048364054}
{'foo': 54, 'bar': 'pears', 'baz': 0.7060235672693753}
{'foo': 58, 'bar': 'pears', 'baz': 0.12677371544592353}
{'foo': 17, 'bar': 'pears', 'baz': 0.2684826823900752}
...

In [5]: table = etl.fromdicts(dummy.dicts())

In [6]: table
Out[6]: 
+-----+-----------+---------------------+
| foo | bar       | baz                 |
+=====+===========+=====================+
|  24 | 'apples'  |  0.9829038224380889 |
+-----+-----------+---------------------+
|  44 | 'oranges' | 0.14938272048364054 |
+-----+-----------+---------------------+
|  54 | 'pears'   |  0.7060235672693753 |
+-----+-----------+---------------------+
|  58 | 'pears'   | 0.12677371544592353 |
+-----+-----------+---------------------+
|  17 | 'pears'   |  0.2684826823900752 |
+-----+-----------+---------------------+
...

In [7]: table.dicts()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [7], line 1
----> 1 table.dicts()

TypeError: 'DictsView' object is not callable