Repository: ray-project/ray
File: python/ray/data/_internal/logical/interfaces/logical_operator.py (Python)

Code before:
        return super().post_order_iter()  # type: ignore

    def _apply_transform(
        self, transform: Callable[["LogicalOperator"], "LogicalOperator"]
    ) -> "LogicalOperator":
        return super()._apply_transform(transform)  # type: ignore

    def _get_args(self) -> Dict[str, Any]:
        """This Dict must be serializable"""
        args: Dict[str, Any] = {}
        for key, value in vars(self).items():
            if key.startswith("_"):
                args[key] = value
            else:
                # Keep underscore-prefixed keys to preserve legacy export schema.
                args[f"_{key}"] = value
        # Preserve legacy export shape even though output deps are no longer tracked.
        args["_output_dependencies"] = []
        return args

    @property
    def dag_str(self) -> str:
        """String representation of the whole DAG."""
        if self.input_dependencies:
            out_str = ", ".join([x.dag_str for x in self.input_dependencies])
            out_str += " -> "
        else:
            out_str = ""
        out_str += f"{self.__class__.__name__}[{self.name}]"
        return out_str

    def __repr__(self) -> str:
        return f"{self.__class__.__name__}[{self.name}]"

    def __str__(self) -> str:
        return repr(self)

    def infer_schema(self) -> Optional["Schema"]:
        """Returns the inferred schema of the output blocks."""
        return None

    def infer_metadata(self) -> "BlockMetadata":
        """A ``BlockMetadata`` that represents the aggregate metadata of the outputs.

        This method is used by methods like :meth:`~ray.data.Dataset.schema` to
        efficiently return metadata.
        """
        return BlockMetadata(None, None, None, None)

    def is_lineage_serializable(self) -> bool:
        """Returns whether the lineage of this operator can be serialized.

Review comment (refactor):
I think this is duplicated with `Operator.dag_str`. If `Operator.name` is non-None, than I think we can just re-use the implementation on the `Operator` base class and remove this

Code after:
    ) -> "LogicalOperator":
        return super()._apply_transform(transform)  # type: ignore

    def _get_args(self) -> Dict[str, Any]:
        """This Dict must be serializable"""
        args: Dict[str, Any] = {}
        for key, value in vars(self).items():
            if key.startswith("_"):
                args[key] = value
            else:
                # Keep underscore-prefixed keys to preserve legacy export schema.
                args[f"_{key}"] = value
        # Preserve legacy export shape even though output deps are no longer tracked.
        args["_output_dependencies"] = []
        return args

    @property
    def dag_str(self) -> str:
        """String representation of the whole DAG."""
        if self.input_dependencies:
            out_str = ", ".join([x.dag_str for x in self.input_dependencies])
            out_str += " -> "
        else:
            out_str = ""
        out_str += f"{self.__class__.__name__}[{self.name}]"
        return out_str

    def __repr__(self) -> str:
        return f"{self.__class__.__name__}[{self.name}]"

    def __str__(self) -> str:
        return repr(self)

    def infer_schema(self) -> Optional["Schema"]:
        """Returns the inferred schema of the output blocks."""
        return None

    def infer_metadata(self) -> "BlockMetadata":
        """A ``BlockMetadata`` that represents the aggregate metadata of the outputs.

        This method is used by methods like :meth:`~ray.data.Dataset.schema` to
        efficiently return metadata.
        """
        return BlockMetadata(None, None, None, None)

    def is_lineage_serializable(self) -> bool:
        """Returns whether the lineage of this operator can be serialized.

        An operator is lineage serializable if you can serialize it on one machine and
        deserialize it on another without losing information. Operators that store
        object references (e.g., ``InputData``) aren't lineage serializable because the