Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
thombashi committed Oct 2, 2021
1 parent ee5a4eb commit 43e3bf9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
3 changes: 1 addition & 2 deletions docs/pages/examples/typehint/javascript.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ You can specify type hints to a writer via
from datetime import datetime
from pytablewriter import JavaScriptTableWriter
from pytablewriter.typehint import DateTime, Integer, String
def main():
writer = JavaScriptTableWriter()
Expand All @@ -27,7 +26,7 @@ You can specify type hints to a writer via
print("// with type hints: values will be converted with type of hints if it possible")
writer.table_name = "with type hint"
writer.type_hints = [Integer, DateTime, String]
writer.type_hints = ["int", "datetime", "str"]
writer.write_table()
if __name__ == "__main__":
Expand Down
3 changes: 1 addition & 2 deletions docs/pages/examples/typehint/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ You can specify type hints to a writer via
from datetime import datetime
from pytablewriter import PythonCodeTableWriter
from pytablewriter.typehint import DateTime, Integer, String
def main():
writer = PythonCodeTableWriter()
Expand All @@ -28,7 +27,7 @@ You can specify type hints to a writer via
# set type hints
writer.table_name = "python variable with type hints"
writer.headers = ["hint_int", "hint_str", "hint_datetime", "hint_str"]
writer.type_hints = [Integer, String, DateTime, String]
writer.type_hints = ["int", "str", "datetime", "str"]
writer.write_table()
if __name__ == "__main__":
Expand Down
21 changes: 10 additions & 11 deletions examples/ipynb/pytablewriter_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,6 @@
"source": [
"from datetime import datetime\n",
"from pytablewriter import JavaScriptTableWriter\n",
"from pytablewriter.typehint import DateTime, Integer, String\n",
"\n",
"\n",
"def main():\n",
Expand All @@ -1070,13 +1069,13 @@
" [0.12, \"2017-02-03 04:05:06\", datetime(2017, 2, 3, 4, 5, 6)],\n",
" ]\n",
"\n",
" print(\"// without type hints: column data types detected automatically by default\")\n",
" print(\"// without type hints: column data types detected automatically by default\")\n",
" writer.table_name = \"without type hint\"\n",
" writer.write_table()\n",
"\n",
" print(\"// with type hints: Integer, DateTime, String\")\n",
" print(\"\\n// with type hints\")\n",
" writer.table_name = \"with type hint\"\n",
" writer.type_hints = [Integer, DateTime, String]\n",
" writer.type_hints = [\"int\", \"datetime\", \"str\"]\n",
" writer.write_table()\n",
"\n",
"\n",
Expand All @@ -1088,13 +1087,14 @@
"output_type": "stream",
"name": "stdout",
"text": [
"// without type hints: column data types detected automatically by default\n",
"// without type hints: column data types detected automatically by default\n",
"const without_type_hint = [\n",
" [\"header_a\", \"header_b\", \"header_c\"],\n",
" [-1.1, \"2017-01-02 03:04:05\", new Date(\"2017-01-02T03:04:05\")],\n",
" [0.12, \"2017-02-03 04:05:06\", new Date(\"2017-02-03T04:05:06\")]\n",
"];\n",
"// with type hints: Integer, DateTime, String\n",
"\n",
"// with type hints\n",
"const with_type_hint = [\n",
" [\"header_a\", \"header_b\", \"header_c\"],\n",
" [-1, new Date(\"2017-01-02T03:04:05\"), \"2017-01-02 03:04:05\"],\n",
Expand All @@ -1111,7 +1111,6 @@
"source": [
"from datetime import datetime\n",
"from pytablewriter import PythonCodeTableWriter\n",
"from pytablewriter.typehint import DateTime, Integer, String\n",
"\n",
"\n",
"def main():\n",
Expand All @@ -1129,7 +1128,7 @@
" # set type hints\n",
" writer.table_name = \"python variable with type hints\"\n",
" writer.headers = [\"hint_int\", \"hint_str\", \"hint_datetime\", \"hint_str\"]\n",
" writer.type_hints = [Integer, String, DateTime, String]\n",
" writer.type_hints = [\"int\", \"datetime\", \"str\"]\n",
" writer.write_table()\n",
"\n",
"\n",
Expand All @@ -1148,8 +1147,8 @@
"]\n",
"python_variable_with_type_hints = [\n",
" [\"hint_int\", \"hint_str\", \"hint_datetime\", \"hint_str\"],\n",
" [-1, \"inf\", dateutil.parser.parse(\"2017-01-02T03:04:05\"), \"2017-01-02 03:04:05\"],\n",
" [0, \"nan\", dateutil.parser.parse(\"2017-02-03T04:05:06\"), \"2017-02-03 04:05:06\"],\n",
" [-1, float(\"inf\"), \"2017-01-02 03:04:05\", dateutil.parser.parse(\"2017-01-02T03:04:05\")],\n",
" [0, float(\"nan\"), \"2017-02-03 04:05:06\", dateutil.parser.parse(\"2017-02-03T04:05:06\")],\n",
"]\n"
]
}
Expand Down Expand Up @@ -1575,7 +1574,7 @@
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3.8.11 64-bit ('3.8.11')"
"display_name": "Python 3.8.11 64-bit ('3.8.11': pyenv)"
},
"language_info": {
"codemirror_mode": {
Expand Down

0 comments on commit 43e3bf9

Please sign in to comment.