Пример #1
0
    def enumerate_collection(_inferred_intent: List[Clause],
                             ldf: LuxDataFrame) -> VisList:
        """
		Given specifications that have been expanded thorught populateOptions,
		recursively iterate over the resulting list combinations to generate a vis list.

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

		Returns
		-------
		VisList: list[lux.Vis]
			vis list with compiled lux.Vis objects.
		"""
        import copy
        intent = Compiler.populate_wildcard_options(_inferred_intent, ldf)
        attributes = intent['attributes']
        filters = intent['filters']
        if len(attributes) == 0 and len(filters) > 0:
            ldf.filter_specs = filters
            return []

        collection = []

        # TODO: generate combinations of column attributes recursively by continuing to accumulate attributes for len(colAtrr) times
        def combine(col_attrs, accum):
            last = (len(col_attrs) == 1)
            n = len(col_attrs[0])
            for i in range(n):
                column_list = copy.deepcopy(accum + [col_attrs[0][i]])
                if last:
                    if len(
                            filters
                    ) > 0:  # if we have filters, generate combinations for each row.
                        for row in filters:
                            _inferred_intent = copy.deepcopy(column_list +
                                                             [row])
                            vis = Vis(
                                _inferred_intent,
                                title=
                                f"{row.attribute} {row.filter_op} {row.value}")
                            collection.append(vis)
                    else:
                        vis = Vis(column_list)
                        collection.append(vis)
                else:
                    combine(col_attrs[1:], column_list)

        combine(attributes, [])
        return VisList(collection)
Пример #2
0
    def enumerateCollection(specLst: List[Spec],
                            ldf: LuxDataFrame) -> ViewCollection:
        """
		Given specifications that have been expanded thorught populateOptions,
		recursively iterate over the resulting list combinations to generate a View collection.

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

		Returns
		-------
		ViewCollection: list[lux.View]
			view collection with compiled lux.View objects.
		"""
        import copy
        specs = Compiler.populateWildcardOptions(specLst, ldf)
        attributes = specs['attributes']
        filters = specs['filters']
        if len(attributes) == 0 and len(filters) > 0:
            ldf.filterSpecs = filters
            return []

        collection = []

        # TODO: generate combinations of column attributes recursively by continuing to accumulate attributes for len(colAtrr) times
        def combine(colAttrs, accum):
            last = (len(colAttrs) == 1)
            n = len(colAttrs[0])
            for i in range(n):
                columnList = copy.deepcopy(accum + [colAttrs[0][i]])
                if last:
                    if len(
                            filters
                    ) > 0:  # if we have filters, generate combinations for each row.
                        for row in filters:
                            specLst = copy.deepcopy(columnList + [row])
                            view = View(
                                specLst,
                                title=
                                f"{row.attribute} {row.filterOp} {row.value}")
                            collection.append(view)
                    else:
                        view = View(columnList)
                        collection.append(view)
                else:
                    combine(colAttrs[1:], columnList)

        combine(attributes, [])
        return ViewCollection(collection)
Пример #3
0
Файл: Vis.py Проект: smritim/lux
 def _repr_html_(self):
     from IPython.display import display
     check_import_lux_widget()
     import luxWidget
     if (self.data is None):
         raise Exception(
             "No data is populated in Vis. In order to generate data required for the vis, use the 'refresh_source' function to populate the Vis with a data source (e.g., vis.refresh_source(df))."
         )
     else:
         from lux.luxDataFrame.LuxDataframe import LuxDataFrame
         widget = luxWidget.LuxWidget(
             currentVis=LuxDataFrame.current_view_to_JSON([self]),
             recommendations=[],
             intent="")
         display(widget)
Пример #4
0
	def _repr_html_(self):
		from IPython.display import display
		check_import_lux_widget()
		import luxWidget
		if (self.data is None):
			raise Exception("No data populated in View. Use the 'load' function (e.g., view.load(df)) to populate the view with a data source.")
		else:
			from lux.luxDataFrame.LuxDataframe import LuxDataFrame
			# widget  = LuxDataFrame.render_widget(input_current_view=self,render_target="viewOnly")
			widget =  luxWidget.LuxWidget(
					currentView= LuxDataFrame.current_view_to_JSON([self]),
					recommendations=[],
					context={}
				)
			display(widget)
Пример #5
0
    def _repr_html_(self):
        self.widget = None
        from IPython.display import display
        from lux.luxDataFrame.LuxDataframe import LuxDataFrame
        # widget  = LuxDataFrame.renderWidget(inputCurrentView=self,renderTarget="viewCollectionOnly")
        recommendation = {
            "action": "View Collection",
            "description": "Shows a view collection defined by the context"
        }
        recommendation["collection"] = self

        checkImportLuxWidget()
        import luxWidget
        recJSON = LuxDataFrame.recToJSON([recommendation])
        self.widget = luxWidget.LuxWidget(currentView={},
                                          recommendations=recJSON,
                                          context={})
        display(self.widget)
Пример #6
0
def pandas_to_lux(df):
    from lux.luxDataFrame.LuxDataframe import LuxDataFrame
    values = df.values.tolist()
    ldf = LuxDataFrame(values, columns=df.columns)
    return (ldf)