Skip to content

PyMeasure

Bases: PyObject

Main class for interacting with measures.

See methods for available functionality.

Source code in pytabular/measure.py
class PyMeasure(PyObject):
    """Main class for interacting with measures.

    See methods for available functionality.
    """

    def __init__(self, object, table) -> None:
        """Connects measure to parent `PyTable`.

        It will also add some custom rows for the `rich`
        table display.

        Args:
            object (object.PyObject): The .Net measure object.
            table (table.PyTable): The parent `PyTable`.
        """
        super().__init__(object)
        self.Table = table
        self._display.add_row("Expression", self._object.Expression, end_section=True)
        self._display.add_row("DisplayFolder", self._object.DisplayFolder)
        self._display.add_row("IsHidden", str(self._object.IsHidden))
        self._display.add_row("FormatString", self._object.FormatString)

    def get_dependencies(self) -> pd.DataFrame:
        """Get the dependant objects of a measure.

        Returns:
            pd.DataFrame: The Return Value is a Pandas dataframe
                            which displays all the dependancies
                            of the object.

        """
        dmv_query = f"select * from $SYSTEM.DISCOVER_CALC_DEPENDENCY where \
            [OBJECT] = '{self.Name}' and [TABLE] = '{self.Table.Name}'"
        return self.Table.Model.query(dmv_query)

__init__(object, table)

Connects measure to parent PyTable.

It will also add some custom rows for the rich table display.

Parameters:

Name Type Description Default
object PyObject

The .Net measure object.

required
table PyTable

The parent PyTable.

required
Source code in pytabular/measure.py
def __init__(self, object, table) -> None:
    """Connects measure to parent `PyTable`.

    It will also add some custom rows for the `rich`
    table display.

    Args:
        object (object.PyObject): The .Net measure object.
        table (table.PyTable): The parent `PyTable`.
    """
    super().__init__(object)
    self.Table = table
    self._display.add_row("Expression", self._object.Expression, end_section=True)
    self._display.add_row("DisplayFolder", self._object.DisplayFolder)
    self._display.add_row("IsHidden", str(self._object.IsHidden))
    self._display.add_row("FormatString", self._object.FormatString)

get_dependencies()

Get the dependant objects of a measure.

Returns:

Type Description
DataFrame

pd.DataFrame: The Return Value is a Pandas dataframe which displays all the dependancies of the object.

Source code in pytabular/measure.py
def get_dependencies(self) -> pd.DataFrame:
    """Get the dependant objects of a measure.

    Returns:
        pd.DataFrame: The Return Value is a Pandas dataframe
                        which displays all the dependancies
                        of the object.

    """
    dmv_query = f"select * from $SYSTEM.DISCOVER_CALC_DEPENDENCY where \
        [OBJECT] = '{self.Name}' and [TABLE] = '{self.Table.Name}'"
    return self.Table.Model.query(dmv_query)