Ejemplo n.º 1
0
def test_dateformatter():
    ldf = pd.read_csv("lux/data/car.csv")
    # change pandas dtype for the column "Year" to datetype
    ldf["Year"] = pd.to_datetime(ldf["Year"], format="%Y")
    timestamp = np.datetime64("2019-08-26")
    ldf.maintain_metadata()
    assert date_utils.date_formatter(timestamp, ldf) == "2019"

    ldf["Year"][0] = np.datetime64("1970-03-01")  # make month non unique

    assert date_utils.date_formatter(timestamp, ldf) == "2019-8"

    ldf["Year"][0] = np.datetime64("1970-03-03")  # make day non unique

    assert date_utils.date_formatter(timestamp, ldf) == "2019-8-26"
Ejemplo n.º 2
0
def test_dateformatter():
    ldf = pd.read_csv("lux/data/car.csv")
    ldf["Year"] = pd.to_datetime(
        ldf["Year"],
        format='%Y')  # change pandas dtype for the column "Year" to datetype
    timestamp = np.datetime64('2019-08-26')

    assert (date_utils.date_formatter(timestamp, ldf) == '2019')

    ldf["Year"][0] = np.datetime64('1970-03-01')  # make month non unique

    assert (date_utils.date_formatter(timestamp, ldf) == '2019-8')

    ldf["Year"][0] = np.datetime64('1970-03-03')  # make day non unique

    assert (date_utils.date_formatter(timestamp, ldf) == '2019-8-26')
Ejemplo n.º 3
0
    def populate_data_type_model(ldf, vlist):
        """
        Given a underspecified Clause, populate the data_type and data_model information accordingly

        Parameters
        ----------
        ldf : lux.core.frame
                LuxDataFrame with underspecified intent

        vis_collection : list[lux.vis.Vis]
                List of lux.Vis objects that will have their underspecified Clause details filled out.
        """
        # TODO: copy might not be neccesary
        from lux.utils.date_utils import is_datetime_string

        data_model_lookup = lux.config.executor.compute_data_model_lookup(
            ldf.data_type)

        for vis in vlist:
            for clause in vis._inferred_intent:
                if clause.description == "?":
                    clause.description = ""
                # TODO: Note that "and not is_datetime_string(clause.attribute))" is a temporary hack and breaks the `test_row_column_group` example
                # and not is_datetime_string(clause.attribute):
                if clause.attribute != "" and clause.attribute != "Record":
                    if clause.data_type == "":
                        clause.data_type = ldf.data_type[clause.attribute]
                    if clause.data_type == "id":
                        clause.data_type = "nominal"
                    if clause.data_type == "geographical":
                        clause.data_type = "nominal"
                    if clause.data_model == "":
                        clause.data_model = data_model_lookup[clause.attribute]
                if clause.value != "":
                    # If user provided title for Vis, then don't override.
                    if vis.title == "":
                        if isinstance(clause.value, np.datetime64):
                            chart_title = date_utils.date_formatter(
                                clause.value, ldf)
                        else:
                            chart_title = clause.value
                        vis.title = f"{clause.attribute} {clause.filter_op} {chart_title}"
            vis._ndim = 0
            vis._nmsr = 0

            for clause in vis._inferred_intent:
                if clause.value == "":
                    if clause.data_model == "dimension":
                        vis._ndim += 1
                    elif clause.data_model == "measure" and clause.attribute != "Record":
                        vis._nmsr += 1
Ejemplo n.º 4
0
    def populate_data_type_model(ldf, vis_collection) -> VisList:
        """
        Given a underspecified Clause, populate the data_type and data_model information accordingly

        Parameters
        ----------
        ldf : lux.core.frame
                LuxDataFrame with underspecified intent

        vis_collection : list[lux.vis.Vis]
                List of lux.Vis objects that will have their underspecified Clause details filled out.
        Returns
        -------
        vlist: VisList
                vis list with compiled lux.Vis objects.
        """
        # TODO: copy might not be neccesary
        from lux.utils.date_utils import is_datetime_string
        import copy

        vlist = copy.deepcopy(vis_collection)  # Preserve the original dobj
        for vis in vlist:
            for clause in vis._inferred_intent:
                if clause.description == "?":
                    clause.description = ""
                # TODO: Note that "and not is_datetime_string(clause.attribute))" is a temporary hack and breaks the `test_row_column_group` example
                if (clause.attribute != "" and clause.attribute != "Record"
                    ):  # and not is_datetime_string(clause.attribute):
                    if clause.data_type == "":
                        clause.data_type = ldf.data_type_lookup[
                            clause.attribute]
                    if clause.data_type == "id":
                        clause.data_type = "nominal"
                    if clause.data_model == "":
                        clause.data_model = ldf.data_model_lookup[
                            clause.attribute]
                if clause.value != "":
                    if (
                            vis.title == ""
                    ):  # If user provided title for Vis, then don't override.
                        if isinstance(clause.value, np.datetime64):
                            chart_title = date_utils.date_formatter(
                                clause.value, ldf)
                        else:
                            chart_title = clause.value
                        vis.title = (
                            f"{clause.attribute} {clause.filter_op} {chart_title}"
                        )
        return vlist
Ejemplo n.º 5
0
    def populate_data_type_model(ldf, vis_collection) -> VisList:
        """
		Given a underspecified Clause, populate the data_type and data_model information accordingly

		Parameters
		----------
		ldf : lux.luxDataFrame.LuxDataFrame
			LuxDataFrame with underspecified intent

		vis_collection : list[lux.vis.Vis]
			List of lux.Vis objects that will have their underspecified Clause details filled out.
		Returns
		-------
		vc: VisList
			vis list with compiled lux.Vis objects.
		"""
        # TODO: copy might not be neccesary
        import copy
        vc = copy.deepcopy(vis_collection)  # Preserve the original dobj
        for vis in vc:
            for clause in vis._inferred_intent:
                if (clause.description == "?"):
                    clause.description = ""
                if (clause.attribute != "" and clause.attribute != "Record"):
                    # if (clause.data_type == ""):
                    clause.data_type = ldf.data_type_lookup[clause.attribute]
                    # if (clause.data_model == ""):
                    clause.data_model = ldf.data_model_lookup[clause.attribute]
                if (clause.value != ""):
                    if (
                            vis.title == ""
                    ):  #If user provided title for Vis, then don't override.
                        if (isinstance(clause.value, np.datetime64)):
                            chart_title = date_utils.date_formatter(
                                clause.value, ldf)
                        else:
                            chart_title = clause.value
                        vis.title = f"{clause.attribute} {clause.filter_op} {chart_title}"
        return vc