From ab53d7e93634bc3c5aab6af323b8a5ab57f1daec Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Thu, 7 Nov 2024 12:44:45 -0800 Subject: [PATCH] /* PR_START p--cte 13 */ Rename `mf_pformat_many`-> `mf_pformat_dict`. --- .../mf_logging/lazy_formattable.py | 4 ++-- .../metricflow_semantics/mf_logging/pretty_print.py | 2 +- .../candidate_push_down/push_down_visitor.py | 4 ++-- .../metricflow_semantics/query/query_resolver.py | 4 ++-- .../collection_helpers/test_pretty_print.py | 8 ++++---- metricflow/data_table/mf_table.py | 6 +++--- tests_metricflow/sql/compare_data_table.py | 10 +++++----- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/metricflow-semantics/metricflow_semantics/mf_logging/lazy_formattable.py b/metricflow-semantics/metricflow_semantics/mf_logging/lazy_formattable.py index b669c26400..e4f994ae34 100644 --- a/metricflow-semantics/metricflow_semantics/mf_logging/lazy_formattable.py +++ b/metricflow-semantics/metricflow_semantics/mf_logging/lazy_formattable.py @@ -5,7 +5,7 @@ from typing_extensions import override -from metricflow_semantics.mf_logging.pretty_print import mf_pformat_many +from metricflow_semantics.mf_logging.pretty_print import mf_pformat_dict class LazyFormat: @@ -52,7 +52,7 @@ def _str_value(self) -> str: message = self._message() else: message = self._message - return mf_pformat_many(message, self._kwargs, preserve_raw_strings=True) + return mf_pformat_dict(message, self._kwargs, preserve_raw_strings=True) @override def __str__(self) -> str: diff --git a/metricflow-semantics/metricflow_semantics/mf_logging/pretty_print.py b/metricflow-semantics/metricflow_semantics/mf_logging/pretty_print.py index 31b021ece3..5b1ffada25 100644 --- a/metricflow-semantics/metricflow_semantics/mf_logging/pretty_print.py +++ b/metricflow-semantics/metricflow_semantics/mf_logging/pretty_print.py @@ -428,7 +428,7 @@ def mf_pformat( # type: ignore return str(obj) -def mf_pformat_many( # type: ignore +def mf_pformat_dict( # type: ignore description: str, obj_dict: Dict[str, Any], max_line_length: int = 120, diff --git a/metricflow-semantics/metricflow_semantics/query/group_by_item/candidate_push_down/push_down_visitor.py b/metricflow-semantics/metricflow_semantics/query/group_by_item/candidate_push_down/push_down_visitor.py index 479a4c1700..18c5981658 100644 --- a/metricflow-semantics/metricflow_semantics/query/group_by_item/candidate_push_down/push_down_visitor.py +++ b/metricflow-semantics/metricflow_semantics/query/group_by_item/candidate_push_down/push_down_visitor.py @@ -14,7 +14,7 @@ from metricflow_semantics.mf_logging.formatting import indent from metricflow_semantics.mf_logging.lazy_formattable import LazyFormat -from metricflow_semantics.mf_logging.pretty_print import mf_pformat, mf_pformat_many +from metricflow_semantics.mf_logging.pretty_print import mf_pformat, mf_pformat_dict from metricflow_semantics.model.semantic_manifest_lookup import SemanticManifestLookup from metricflow_semantics.model.semantics.element_filter import LinkableElementFilter from metricflow_semantics.query.group_by_item.candidate_push_down.group_by_item_candidate import GroupByItemCandidateSet @@ -82,7 +82,7 @@ def __post_init__(self) -> None: # noqa: D105 # If there are errors, there shouldn't be any candidate sets. assert (not self.issue_set.has_errors and not self.candidate_set.is_empty) or ( self.issue_set.has_errors and self.candidate_set.is_empty - ), mf_pformat_many( + ), mf_pformat_dict( "candidate_set / issue_set mismatch:", {"candidate_set": self.candidate_set, "issue_set": self.issue_set} ) diff --git a/metricflow-semantics/metricflow_semantics/query/query_resolver.py b/metricflow-semantics/metricflow_semantics/query/query_resolver.py index 0469bf633e..76eb0a57e0 100644 --- a/metricflow-semantics/metricflow_semantics/query/query_resolver.py +++ b/metricflow-semantics/metricflow_semantics/query/query_resolver.py @@ -8,7 +8,7 @@ from dbt_semantic_interfaces.references import MeasureReference, MetricReference, SemanticModelReference from metricflow_semantics.mf_logging.lazy_formattable import LazyFormat -from metricflow_semantics.mf_logging.pretty_print import mf_pformat, mf_pformat_many +from metricflow_semantics.mf_logging.pretty_print import mf_pformat, mf_pformat_dict from metricflow_semantics.mf_logging.runtime import log_runtime from metricflow_semantics.model.semantic_manifest_lookup import SemanticManifestLookup from metricflow_semantics.model.semantic_model_derivation import SemanticModelDerivation @@ -557,7 +557,7 @@ def _resolve_query(self, resolver_input_for_query: ResolverInputForQuery) -> Met if len(models_not_in_manifest) > 0: logger.error( LazyFormat( - lambda: mf_pformat_many( + lambda: mf_pformat_dict( "Semantic references that aren't in the manifest were found in the set used in " "a query. This is a bug, and to avoid potential issues, they will be filtered out.", {"models_not_in_manifest": models_not_in_manifest}, diff --git a/metricflow-semantics/tests_metricflow_semantics/collection_helpers/test_pretty_print.py b/metricflow-semantics/tests_metricflow_semantics/collection_helpers/test_pretty_print.py index d637151d9e..1c9bdde491 100644 --- a/metricflow-semantics/tests_metricflow_semantics/collection_helpers/test_pretty_print.py +++ b/metricflow-semantics/tests_metricflow_semantics/collection_helpers/test_pretty_print.py @@ -9,7 +9,7 @@ from dbt_semantic_interfaces.type_enums import DimensionType from metricflow_semantics.mf_logging.formatting import indent from metricflow_semantics.mf_logging.pretty_formattable import MetricFlowPrettyFormattable -from metricflow_semantics.mf_logging.pretty_print import mf_pformat, mf_pformat_many +from metricflow_semantics.mf_logging.pretty_print import mf_pformat, mf_pformat_dict from metricflow_semantics.test_helpers.metric_time_dimension import MTD_SPEC_DAY from typing_extensions import override @@ -145,7 +145,7 @@ def test_pydantic_model() -> None: # noqa: D103 def test_pformat_many() -> None: # noqa: D103 - result = mf_pformat_many("Example description:", obj_dict={"object_0": (1, 2, 3), "object_1": {4: 5}}) + result = mf_pformat_dict("Example description:", obj_dict={"object_0": (1, 2, 3), "object_1": {4: 5}}) assert ( textwrap.dedent( @@ -160,7 +160,7 @@ def test_pformat_many() -> None: # noqa: D103 def test_pformat_many_with_raw_strings() -> None: # noqa: D103 - result = mf_pformat_many("Example description:", obj_dict={"object_0": "foo\nbar"}, preserve_raw_strings=True) + result = mf_pformat_dict("Example description:", obj_dict={"object_0": "foo\nbar"}, preserve_raw_strings=True) assert ( textwrap.dedent( @@ -176,7 +176,7 @@ def test_pformat_many_with_raw_strings() -> None: # noqa: D103 def test_pformat_many_with_strings() -> None: # noqa: D103 - result = mf_pformat_many("Example description:", obj_dict={"object_0": "foo\nbar"}) + result = mf_pformat_dict("Example description:", obj_dict={"object_0": "foo\nbar"}) assert ( textwrap.dedent( """\ diff --git a/metricflow/data_table/mf_table.py b/metricflow/data_table/mf_table.py index e7136a420f..5ad883baab 100644 --- a/metricflow/data_table/mf_table.py +++ b/metricflow/data_table/mf_table.py @@ -9,7 +9,7 @@ import tabulate from metricflow_semantics.mf_logging.formatting import indent -from metricflow_semantics.mf_logging.pretty_print import mf_pformat, mf_pformat_many +from metricflow_semantics.mf_logging.pretty_print import mf_pformat, mf_pformat_dict from typing_extensions import Self from metricflow.data_table.column_types import CellValue, InputCellValue, row_cell_types @@ -47,7 +47,7 @@ def __post_init__(self) -> None: # noqa: D105 # Check that the type of the object in the rows match. for column_index, cell_value in enumerate(row): expected_cell_value_type = self.column_descriptions[column_index].column_type - assert cell_value is None or isinstance(cell_value, expected_cell_value_type), mf_pformat_many( + assert cell_value is None or isinstance(cell_value, expected_cell_value_type), mf_pformat_dict( "Cell value type mismatch.", { "row_index": row_index, @@ -59,7 +59,7 @@ def __post_init__(self) -> None: # noqa: D105 ) # Check that datetimes don't have a timezone set. if isinstance(cell_value, datetime.datetime): - assert cell_value.tzinfo is None, mf_pformat_many( + assert cell_value.tzinfo is None, mf_pformat_dict( "Time zone provided for datetime.", { "row_index": row_index, diff --git a/tests_metricflow/sql/compare_data_table.py b/tests_metricflow/sql/compare_data_table.py index 8fb8f876bc..2e47cae5b6 100644 --- a/tests_metricflow/sql/compare_data_table.py +++ b/tests_metricflow/sql/compare_data_table.py @@ -6,7 +6,7 @@ from dataclasses import dataclass from typing import Dict, Optional, SupportsFloat -from metricflow_semantics.mf_logging.pretty_print import mf_pformat_many +from metricflow_semantics.mf_logging.pretty_print import mf_pformat_dict from metricflow.data_table.column_types import CellValue from metricflow.data_table.mf_table import MetricFlowDataTable @@ -106,7 +106,7 @@ def check_data_tables_are_equal( if expected_table.column_names != actual_table.column_names: raise ValueError( - mf_pformat_many( + mf_pformat_dict( "Column descriptions do not match.", { "expected_table_column_names": expected_table.column_names, @@ -117,7 +117,7 @@ def check_data_tables_are_equal( if expected_table.row_count != actual_table.row_count: raise ValueError( - mf_pformat_many( + mf_pformat_dict( "Row counts do not match.", dict( **{ @@ -132,7 +132,7 @@ def check_data_tables_are_equal( if not allow_empty and expected_table.row_count == 0: raise ValueError( - mf_pformat_many( + mf_pformat_dict( f"Expected table is empty and {allow_empty=}. This may indicate an error in configuring the test.", _generate_table_diff_fields(expected_table=expected_table, actual_table=actual_table), preserve_raw_strings=True, @@ -143,7 +143,7 @@ def check_data_tables_are_equal( if mismatch is not None: raise ValueError( - mf_pformat_many( + mf_pformat_dict( mismatch.message, dict( **{