Exemple #1
0
    def _ingest_quotes_featureset(self):
        quotes_set = FeatureSet("stock-quotes", entities=[Entity("ticker")])

        flow = quotes_set.graph
        flow.to("MyMap", multiplier=3).to("storey.Extend",
                                          _fn="({'z': event['bid'] * 77})").to(
                                              "storey.Filter",
                                              "filter",
                                              _fn="(event['bid'] > 51.92)").to(
                                                  FeaturesetValidator())

        quotes_set.add_aggregation("asks", "ask", ["sum", "max"], ["1h", "5h"],
                                   "10m")
        quotes_set.add_aggregation("bids", "bid", ["min", "max"], ["1h"],
                                   "10m")

        df = fs.infer_metadata(
            quotes_set,
            quotes,
            entity_columns=["ticker"],
            timestamp_key="time",
            options=fs.InferOptions.default(),
        )
        self._logger.info(f"quotes spec: {quotes_set.spec.to_yaml()}")
        assert df["zz"].mean() == 9, "map didnt set the zz column properly"
        quotes_set["bid"].validator = MinMaxValidator(min=52, severity="info")

        quotes_set.plot(str(self.results_path / "pipe.png"),
                        rankdir="LR",
                        with_targets=True)
        df = fs.ingest(quotes_set, quotes, return_df=True)
        self._logger.info(f"output df:\n{df}")
        assert quotes_set.status.stats.get("asks_sum_1h"), "stats not created"
Exemple #2
0
def test_feature_set():
    myset = FeatureSet("set1", entities=[Entity("key")])
    myset["f1"] = Feature(ValueType.INT64, description="my f1")

    assert list(myset.spec.entities.keys()) == ["key"], "index wasnt set"
    assert list(myset.spec.features.keys()) == ["f1"], "feature wasnt set"