Rename --xlab to --x-label, X_TITLE to X_LABEL, same for y (#3948)

Renamed:
- cli options
- dvcfile plot props
- template anchors
- variable names throughout the code
This commit is contained in:
Alexander Schepanovski
2020-06-03 20:30:17 +03:00
committed by GitHub
parent ff54ac1bfb
commit 9a55b909f8
8 changed files with 29 additions and 27 deletions
+2 -2
View File
@@ -197,8 +197,8 @@ def _add_props_arguments(parser):
help="Provided CSV ot TSV datafile does not have a header.", help="Provided CSV ot TSV datafile does not have a header.",
) )
parser.add_argument("--title", default=None, help="Plot title.") parser.add_argument("--title", default=None, help="Plot title.")
parser.add_argument("--xlab", default=None, help="X axis title.") parser.add_argument("--x-label", default=None, help="X axis label.")
parser.add_argument("--ylab", default=None, help="Y axis title.") parser.add_argument("--y-label", default=None, help="Y axis lebel.")
def _add_output_arguments(parser): def _add_output_arguments(parser):
+2 -2
View File
@@ -58,8 +58,8 @@ class BaseOutput:
PARAM_PLOT_TEMPLATE = "template" PARAM_PLOT_TEMPLATE = "template"
PARAM_PLOT_X = "x" PARAM_PLOT_X = "x"
PARAM_PLOT_Y = "y" PARAM_PLOT_Y = "y"
PARAM_PLOT_XLAB = "xlab" PARAM_PLOT_X_LABEL = "x_label"
PARAM_PLOT_YLAB = "ylab" PARAM_PLOT_Y_LABEL = "y_label"
PARAM_PLOT_TITLE = "title" PARAM_PLOT_TITLE = "title"
PARAM_PLOT_CSV_HEADER = "csv_header" PARAM_PLOT_CSV_HEADER = "csv_header"
PARAM_PERSIST = "persist" PARAM_PERSIST = "persist"
+13 -12
View File
@@ -38,8 +38,8 @@ class Template:
X_ANCHOR = "<DVC_METRIC_X>" X_ANCHOR = "<DVC_METRIC_X>"
Y_ANCHOR = "<DVC_METRIC_Y>" Y_ANCHOR = "<DVC_METRIC_Y>"
TITLE_ANCHOR = "<DVC_METRIC_TITLE>" TITLE_ANCHOR = "<DVC_METRIC_TITLE>"
X_TITLE_ANCHOR = "<DVC_METRIC_X_TITLE>" X_LABEL_ANCHOR = "<DVC_METRIC_X_LABEL>"
Y_TITLE_ANCHOR = "<DVC_METRIC_Y_TITLE>" Y_LABEL_ANCHOR = "<DVC_METRIC_Y_LABEL>"
def __init__(self, templates_dir): def __init__(self, templates_dir):
self.plot_templates_dir = templates_dir self.plot_templates_dir = templates_dir
@@ -119,15 +119,15 @@ class Template:
@staticmethod @staticmethod
def _replace_metadata_anchors(result_content, props): def _replace_metadata_anchors(result_content, props):
props.setdefault("title", "") props.setdefault("title", "")
props.setdefault("xlab", props.get("x")) props.setdefault("x_label", props.get("x"))
props.setdefault("ylab", props.get("y")) props.setdefault("y_label", props.get("y"))
replace_pairs = [ replace_pairs = [
(Template.TITLE_ANCHOR, "title"), (Template.TITLE_ANCHOR, "title"),
(Template.X_ANCHOR, "x"), (Template.X_ANCHOR, "x"),
(Template.Y_ANCHOR, "y"), (Template.Y_ANCHOR, "y"),
(Template.X_TITLE_ANCHOR, "xlab"), (Template.X_LABEL_ANCHOR, "x_label"),
(Template.Y_TITLE_ANCHOR, "ylab"), (Template.Y_LABEL_ANCHOR, "y_label"),
] ]
for anchor, key in replace_pairs: for anchor, key in replace_pairs:
value = props.get(key) value = props.get(key)
@@ -170,12 +170,12 @@ class DefaultLinearTemplate(Template):
"x": { "x": {
"field": Template.X_ANCHOR, "field": Template.X_ANCHOR,
"type": "quantitative", "type": "quantitative",
"title": Template.X_TITLE_ANCHOR, "title": Template.X_LABEL_ANCHOR,
}, },
"y": { "y": {
"field": Template.Y_ANCHOR, "field": Template.Y_ANCHOR,
"type": "quantitative", "type": "quantitative",
"title": Template.Y_TITLE_ANCHOR, "title": Template.Y_LABEL_ANCHOR,
"scale": {"zero": False}, "scale": {"zero": False},
}, },
"color": {"field": "rev", "type": "nominal"}, "color": {"field": "rev", "type": "nominal"},
@@ -195,13 +195,13 @@ class DefaultConfusionTemplate(Template):
"field": Template.X_ANCHOR, "field": Template.X_ANCHOR,
"type": "nominal", "type": "nominal",
"sort": "ascending", "sort": "ascending",
"title": Template.X_TITLE_ANCHOR, "title": Template.X_LABEL_ANCHOR,
}, },
"y": { "y": {
"field": Template.Y_ANCHOR, "field": Template.Y_ANCHOR,
"type": "nominal", "type": "nominal",
"sort": "ascending", "sort": "ascending",
"title": Template.Y_TITLE_ANCHOR, "title": Template.Y_LABEL_ANCHOR,
}, },
"color": {"aggregate": "count", "type": "quantitative"}, "color": {"aggregate": "count", "type": "quantitative"},
"facet": {"field": "rev", "type": "nominal"}, "facet": {"field": "rev", "type": "nominal"},
@@ -220,12 +220,12 @@ class DefaultScatterTemplate(Template):
"x": { "x": {
"field": Template.X_ANCHOR, "field": Template.X_ANCHOR,
"type": "quantitative", "type": "quantitative",
"title": Template.X_TITLE_ANCHOR, "title": Template.X_LABEL_ANCHOR,
}, },
"y": { "y": {
"field": Template.Y_ANCHOR, "field": Template.Y_ANCHOR,
"type": "quantitative", "type": "quantitative",
"title": Template.Y_TITLE_ANCHOR, "title": Template.Y_LABEL_ANCHOR,
"scale": {"zero": False}, "scale": {"zero": False},
}, },
"color": {"field": "rev", "type": "nominal"}, "color": {"field": "rev", "type": "nominal"},
@@ -275,6 +275,7 @@ class PlotTemplates:
def __init__(self, dvc_dir): def __init__(self, dvc_dir):
self.dvc_dir = dvc_dir self.dvc_dir = dvc_dir
print("PlotTemplates.__init__")
if not os.path.exists(self.templates_dir): if not os.path.exists(self.templates_dir):
makedirs(self.templates_dir, exist_ok=True) makedirs(self.templates_dir, exist_ok=True)
+2 -2
View File
@@ -34,8 +34,8 @@ PLOT_PROPS = {
BaseOutput.PARAM_PLOT_TEMPLATE: str, BaseOutput.PARAM_PLOT_TEMPLATE: str,
BaseOutput.PARAM_PLOT_X: str, BaseOutput.PARAM_PLOT_X: str,
BaseOutput.PARAM_PLOT_Y: str, BaseOutput.PARAM_PLOT_Y: str,
BaseOutput.PARAM_PLOT_XLAB: str, BaseOutput.PARAM_PLOT_X_LABEL: str,
BaseOutput.PARAM_PLOT_YLAB: str, BaseOutput.PARAM_PLOT_Y_LABEL: str,
BaseOutput.PARAM_PLOT_TITLE: str, BaseOutput.PARAM_PLOT_TITLE: str,
BaseOutput.PARAM_PLOT_CSV_HEADER: bool, BaseOutput.PARAM_PLOT_CSV_HEADER: bool,
} }
+3 -2
View File
@@ -47,8 +47,9 @@ _dvc_move_COMPGEN=_dvc_compgen_files
_dvc_params='diff' _dvc_params='diff'
_dvc_params_diff='--all --show-json --show-md --no-path' _dvc_params_diff='--all --show-json --show-md --no-path'
_dvc_plots='show diff' _dvc_plots='show diff'
_dvc_plots_show='-t --template -o --out -x -y --show-json --no-csv-header --title --xlab --ylab' _dvc_plots_show='-t --template -o --out -x -y --show-json --no-csv-header --title --x-label --y-label'
_dvc_plots_diff='-t --template --targets -o --out -x -y --show-json --no-csv-header --title --xlab --ylab' _dvc_plots_diff='-t --template --targets -o --out -x -y --show-json --no-csv-header --title --x-label --y-label'
_dvc_plots_modify='-t --template -x -y --no-csv-header --title --x-label --y-label'
_dvc_pull='-j --jobs -r --remote -a --all-branches -T --all-tags -f --force -d --with-deps -R --recursive' _dvc_pull='-j --jobs -r --remote -a --all-branches -T --all-tags -f --force -d --with-deps -R --recursive'
_dvc_pull_COMPGEN=_dvc_compgen_DVCFiles _dvc_pull_COMPGEN=_dvc_compgen_DVCFiles
_dvc_push='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -R --recursive' _dvc_push='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -R --recursive'
+1 -1
View File
@@ -217,7 +217,7 @@ _dvc_push=(
) )
_dvc_plots=( _dvc_plots=(
"1:Sub command:(show diff)" "1:Sub command:(show diff modify)"
) )
_dvc_remote=( _dvc_remote=(
+2 -2
View File
@@ -50,8 +50,8 @@ def test_plot_csv_one_column(tmp_dir, scm, dvc, run_copy_metrics):
props = { props = {
"csv_header": False, "csv_header": False,
"xlab": "x_title", "x_label": "x_title",
"ylab": "y_title", "y_label": "y_title",
"title": "mytitle", "title": "mytitle",
} }
plot_string = dvc.plots.show(props=props)["metric.csv"] plot_string = dvc.plots.show(props=props)["metric.csv"]
+4 -4
View File
@@ -20,9 +20,9 @@ def test_metrics_diff(dvc, mocker):
"y_field", "y_field",
"--title", "--title",
"my_title", "my_title",
"--xlab", "--x-label",
"x_title", "x_title",
"--ylab", "--y-label",
"y_title", "y_title",
"HEAD", "HEAD",
"tag1", "tag1",
@@ -47,8 +47,8 @@ def test_metrics_diff(dvc, mocker):
"x": "x_field", "x": "x_field",
"y": "y_field", "y": "y_field",
"title": "my_title", "title": "my_title",
"xlab": "x_title", "x_label": "x_title",
"ylab": "y_title", "y_label": "y_title",
}, },
) )