Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
),
),
]
exception_test_data_list = [
Data(
table="",
indent=0,
header=[],
value=[],
is_formatting_float=True,
expected=ptw.EmptyTableDataError,
)
]
table_writer_class = ptw.MarkdownTableWriter
def trans_func(value):
if value is None:
return ""
if value is True:
return "X"
if value is False:
return ""
return value
class Test_MarkdownTableWriter_write_new_line(object):
def test_normal(self, capsys):
writer = table_writer_class()
writer.write_null_line()
def print_comparative_times_table(cfg, runs: GroupedRuns, pfile=sys.stdout):
writer = pytablewriter.MarkdownTableWriter()
vs_str = ("{}" + (" vs. {}" * (len(runs.target_names) - 1))).format(
*runs.target_names)
writer.header_list = ["bench name", "x", *runs.target_names]
writer.value_matrix = []
writer.margin = 1
writer.stream = pfile
std_results = get_standard_results(runs)
important_commands = {}
for bench_name, target_to_benchlist in runs.items():
if 'ibd' in bench_name or 'reindex' in bench_name:
important_commands[bench_name] = _condense_bitcoin_cmd(
list(target_to_benchlist.items())[0][1].command)
cmd_writer = pytablewriter.MarkdownTableWriter()
df.loc[step, column_name] = value
if steps:
df = df[steps, :]
df = df.sort_index(ascending=False)
# index to column. and re-order column.
df["step"] = df.index
df = df[["step"] + columns]
output_csv = os.path.join(output_dir, "{}.csv".format(output_file_base))
df.to_csv(output_csv, index=False)
output_md = os.path.join(output_dir, "{}.md".format(output_file_base))
writer = pytablewriter.MarkdownTableWriter()
writer.char_left_side_row = "|" # fix for github
writer.from_dataframe(df)
with open(output_md, "w") as file_stream:
writer.stream = file_stream
writer.write_table()
message = """
output success
output csv: {}
output md: {}
""".format(output_csv, output_md)
print(message)
def convert(filename, from_ext, to_ext):
# provide index for the md file
helpers.add_index_col(filename)
indexed_filename = f"{filename}_temp.{from_ext}"
writer = pytablewriter.MarkdownTableWriter()
writer.from_csv(indexed_filename)
with open(f"./{filename}.{to_ext}", "w") as f:
writer.table_name = "Internships"
writer.stream = f
writer.write_table()
from textwrap import dedent
import pytablewriter
filename = "sample.csv"
with io.open(filename, "w", encoding="utf8") as f:
f.write(dedent("""\
"i","f","c","if","ifc","bool","inf","nan","mix_num","time"
1,1.10,"aa",1.0,"1",True,Infinity,NaN,1,"2017-01-01 00:00:00+09:00"
2,2.20,"bbb",2.2,"2.2",False,Infinity,NaN,Infinity,"2017-01-02 03:04:05+09:00"
3,3.33,"cccc",-3.0,"ccc",True,Infinity,NaN,NaN,"2017-01-01 00:00:00+09:00"
"""))
writer = pytablewriter.MarkdownTableWriter()
writer.from_csv(filename)
writer.write_table()
def write_table(tracks, output_path):
writer = pytablewriter.MarkdownTableWriter()
writer.header_list = ['Title', 'Artist', 'Album', 'User', 'Added at']
value_matrix = []
for track in tracks:
print(track['title'])
cur = [
get_md_link(track['title'], track['track_url']),
', '.join(map(lambda x: x['name'], track['artists'])),
track['album']['name'],
get_md_link(track['user']['name'], track['user']['url']),
track['added_at'].strftime('%Y-%m-%d')
]
value_matrix.append(cur)
writer.value_matrix = value_matrix
with open(output_path, 'w') as f:
writer.stream = f
writer.write_table()
def _tabulate(data, format="markdown"):
"""Return data in specified format"""
format_writers = {
"markdown": MarkdownTableWriter,
"rst": RstSimpleTableWriter,
"html": HtmlTableWriter,
}
writer = format_writers[format]()
if format != "html":
writer.margin = 1
if isinstance(data, dict):
header_list = list(data.keys())
writer.value_matrix = [data]
else: # isinstance(data, list):
header_list = sorted(set().union(*(d.keys() for d in data)))
writer.value_matrix = data
# Move downloads last
#!/usr/bin/env python
# encoding: utf-8
"""
.. codeauthor:: Tsuyoshi Hombashi
"""
from __future__ import print_function
import pytablewriter
import six
writer = pytablewriter.MarkdownTableWriter()
writer.table_name = "zone"
writer.headers = ["zone_id", "country_code", "zone_name"]
writer.value_matrix = [
["1", "AD", "Europe/Andorra"],
["2", "AE", "Asia/Dubai"],
["3", "AF", "Asia/Kabul"],
["4", "AG", "America/Antigua"],
["5", "AI", "America/Anguilla"],
]
# writer instance writes a table to stdout by default
writer.write_table()
# change the stream to a string buffer to get the output as a string
# you can also get tabular text by using dumps method
writer.stream = six.StringIO()