Repository: jazzband/tablib (python)

Issue:
RST - field with one or more space(s) in a string raises ValueError: max() arg is an empty sequence
Dataset.get_rst raises exception if there's a field with one or more space(s) in a string:
The background is actually that I wanted to create an empty row, but rst apparently ignored a line with only "" and so I came across this error.

Python 3.6.6
tablib v2.0.0

```
import tablib
recs = [
  {"name": "john", "desc":"some guy"},
  {"name": "mary", "desc": " "},  # note a space in desc
]
t = tablib.Dataset()
t.dict = recs
t.get_rst()
```
```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\WinPython-64bit-3.6.6.2Qt5\python-3.6.6.amd64\lib\site-packages\tablib\core.py", line 240, in _get_in_format
    return registry.get_format(fmt_key).export_set(self, **kwargs)
  File "D:\WinPython-64bit-3.6.6.2Qt5\python-3.6.6.amd64\lib\site-packages\tablib\formats\_rst.py", line 244, in export_set
    column_widths = cls._get_column_widths(dataset, max_table_width)
  File "D:\WinPython-64bit-3.6.6.2Qt5\python-3.6.6.amd64\lib\site-packages\tablib\formats\_rst.py", line 94, in _get_column_widths
    str_lens, word_lens = cls._get_column_string_lengths(dataset)
  File "D:\WinPython-64bit-3.6.6.2Qt5\python-3.6.6.amd64\lib\site-packages\tablib\formats\_rst.py", line 53, in _get_column_string_lengths
    word_lens[i] = max(word_lens[i], _max_word_len(text))
  File "D:\WinPython-64bit-3.6.6.2Qt5\python-3.6.6.amd64\lib\site-packages\tablib\formats\_rst.py", line 27, in _max_word_len
    return max(len(word) for word in text.split()) if text else 0
ValueError: max() arg is an empty sequence
```


Pull request:
Fixes #469 - Prevented rst crash with only-space strings
Thanks nexone for the report.

Patch:
diff --git a/HISTORY.md b/HISTORY.md
index 12b8fc6..1a90bb0 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -1,5 +1,11 @@
 # History
 
+## Unreleased
+
+### Bugfixes
+
+- Prevented crash in rst export with only-space strings (#469).
+
 ## 2.0.0 (2020-05-16)
 
 ### Breaking changes
diff --git a/src/tablib/formats/_rst.py b/src/tablib/formats/_rst.py
index 6dce91f..afbf1ca 100644
--- a/src/tablib/formats/_rst.py
+++ b/src/tablib/formats/_rst.py
@@ -24,7 +24,7 @@ def _max_word_len(text):
     >>> _max_word_len('Python Module for Tabular Datasets')
     8
     """
-    return max(len(word) for word in text.split()) if text else 0
+    return max([len(word) for word in text.split()], default=0) if text else 0
 
 
 class ReSTFormat:


Test patch:
diff --git a/tests/test_tablib.py b/tests/test_tablib.py
index 3efc87f..f4c0109 100755
--- a/tests/test_tablib.py
+++ b/tests/test_tablib.py
@@ -659,6 +659,7 @@ class RSTTests(BaseTestCase):
         data.headers = self.headers
         data.append(self.john)
         data.append(('Wendy', '', 43))
+        data.append(('Esther', ' ', 31))
         self.assertEqual(
             data.export('rst'),
             '==========  =========  ===\n'
@@ -666,6 +667,7 @@ class RSTTests(BaseTestCase):
             '==========  =========  ===\n'
             'John        Adams      90 \n'
             'Wendy                  43 \n'
+            'Esther                 31 \n'
             '==========  =========  ==='
         )