code: def fetch_data_by_list(self, entities: List[str], limit=50000):
          
  
          if not len(set([e.split(".")[0] for e in entities])) == 1:
              print("Error: entities must be from same domain.")
              return
  
          if len(entities) == 1:
              print("Must pass more than 1 entity.")
              return
          query = text(
              """
              SELECT entity_id, state, last_changed
              FROM states
              WHERE entity_id in ({})
              AND NOT state='unknown'
              ORDER BY last_changed DESC
              LIMIT :limit
              """.format(
                  ",".join("'{}'".format(ent) for ent in entities)
              )
          )
  
          response = self.perform_query(query, limit=limit)
          df = pd.DataFrame(response.fetchall())
          df.columns = ["entity", "state", "last_changed"]
          df = df.set_index("last_changed")  # Set the index on datetime
          df.index = pd.to_datetime(df.index, errors="ignore", utc=True)
          try:
              df["state"] = (
                  df["state"].mask(df["state"].eq("None")).dropna().astype(float)
              )
              df = df.pivot_table(index="last_changed", columns="entity", values="state")
              df = df.fillna(method="ffill")
              df = df.dropna()  # Drop any remaining nan.
              return df
          except:
              print("Error: entities were not all numericals, unformatted df.")
              return df
docs: Basic query from list of entities. Must be from same domain.
          Attempts to unpack lists up to 2 deep.
  
          Parameters
          ----------
          entities : a list of entities
  
          returns a df