thombashi / pytablewriter

pytablewriter is a Python library to write a table in various formats: AsciiDoc / CSV / Elasticsearch / HTML / JavaScript / JSON / LaTeX / LDJSON / LTSV / Markdown / MediaWiki / NumPy / Excel / Pandas / Python / reStructuredText / SQLite / TOML / TSV.
https://pytablewriter.rtfd.io/
MIT License
610 stars 43 forks source link

Markdown save result as file fails #52

Closed rutsam closed 3 years ago

rutsam commented 3 years ago

Problem

In version 0.64.0 and version 0.63.0, whenever I want to save the markdown result in a file I get an error, I tried using python3.6 and python 3.8. The error comes when I use write.dumps or save file using stream and write table as it can be seen in the code below

preview of code that generates error

with open("sample.md", "w") as f:                                                                                           
writer.stream = f                                                                                                       
writer.write_table()  

Error

 File "result.py", line 51, in <module>
    main()
  File "result.py", line 42, in main
    publish_report(report, gral_values, "DIETClassifier")
  File "result.py", line 20, in publish_report
    writer.write_table()
  File "/home/.local/lib/python3.8/site-packages/pytablewriter/writer/text/_markdown.py", line 140, in write_table
    self._write_table(**kwargs)
  File "/home/.local/lib/python3.8/site-packages/pytablewriter/writer/text/_text_writer.py", line 322, in _write_table
    self._preprocess()
  File "/home/.local/lib/python3.8/site-packages/pytablewriter/writer/_table_writer.py", line 1193, in _preprocess
    self._preprocess_table_dp()
  File "/home/.local/lib/python3.8/site-packages/pytablewriter/writer/_table_writer.py", line 1130, in _preprocess_table_dp
    self._table_value_dp_matrix = self._dp_extractor.to_dp_matrix(
  File "/home/.local/lib/python3.8/site-packages/dataproperty/_extractor.py", line 483, in to_dp_matrix
    return self.__to_dp_matrix_st(value_matrix)
  File "/home/.local/lib/python3.8/site-packages/dataproperty/_extractor.py", line 633, in __to_dp_matrix_st
    zip(
  File "/home/.local/lib/python3.8/site-packages/dataproperty/_extractor.py", line 635, in <genexpr>
    _to_dp_list_helper(
  File "/home/.local/lib/python3.8/site-packages/dataproperty/_extractor.py", line 799, in _to_dp_list_helper
    extractor._to_dp_list(data_list, type_hint=type_hint, preprocessor=preprocessor),
  File "/home/.local/lib/python3.8/site-packages/dataproperty/_extractor.py", line 696, in _to_dp_list
    dataprop = self.__to_dp(
  File "/home/.local/lib/python3.8/site-packages/dataproperty/_extractor.py", line 568, in __to_dp
    return self.__to_dp_raw(
  File "/home/.local/lib/python3.8/site-packages/dataproperty/_extractor.py", line 619, in __to_dp_raw
    value_dp = DataProperty(
  File "/home/.local/lib/python3.8/site-packages/dataproperty/_dataproperty.py", line 89, in __init__
    data, no_ansi_escape_data = preprocessor.preprocess(data)
  File "/home/.local/lib/python3.8/site-packages/dataproperty/_preprocessor.py", line 68, in preprocess
    data, no_ansi_escape_data = self.__preprocess_string(
  File "/home/.local/lib/python3.8/site-packages/dataproperty/_preprocessor.py", line 105, in __preprocess_string
    data = self.__dequote(data)
  File "/home/.local/lib/python3.8/site-packages/dataproperty/_preprocessor.py", line 135, in __dequote
    if (s[0] == s[-1]) and s.startswith(("'", '"')):
  KeyError: 0

Stable version

From version 0.62.0 and lower the files were saved without any problem

thombashi commented 3 years ago

@rutsam Thank you for your report.

Would you possibly provide the failed input data (sample.md) ? I could not reproduce the error. According to the error log, the error seems to occur only with certain input data.

thombashi commented 3 years ago

I believe the problem fixed at pytablewriter 0.64.1 Please try to upgrade the package.

Feel free to reopen if you still have any problems about the issue.