Example #1
0
    def get_data(self, header, date_from=None, date_to=None):
        """Load data based on header and dates."""
        cond_header = "index == {}".format(list(header.values))
        cond_date = ("obs_date >= Timestamp('{}') and " +
                     "obs_date <= Timestamp('{}')").format(date_from, date_to)

        query = TableQuery(cond_header).and_(TableQuery(cond_date))

        # call to db
        res = self.filter(query)

        return res
Example #2
0
    def test_filter(self):
        """
        """
        qry_1 = TableQuery(condition="index < -3")
        qry_2 = TableQuery(condition="col_1 > 0").or_(
            TableQuery("col_2 > 0"))
        qry_3 = TableQuery(condition=self.opt_cols[0] + " == 1")
        # qry_4 = TableQuery("index == 2").or_(TableQuery("index == 1"))

        self.assertTrue(self.table.filter(qry_1).empty)
        self.assertTrue(self.test_df.columns.equals(
            self.table.filter(qry_2).columns))
        self.assertEqual(
            self.table.filter(qry_3).loc[:, self.opt_cols[0]].iloc[0], 1)
Example #3
0
    def get_id(self, info, create=False):
        """Fetch integer header ids based on query in `info`.

        Parameters
        ----------
        info : pandas.Series or pandas.DataFrame or dict
        create : bool
            True to create a Header if not found

        Returns
        -------
        res : int or pandas.Series

        """
        # to ndframe
        info_ndframe = self._coerce_to_ndframe(info)

        # fetch
        info_int = self._from_ndframe(info_ndframe)

        # add a new entry if asked
        if create:
            self.add_new(info_int)

        # call to db
        query = TableQuery(info_int)
        header = self.get_unique_id(query=query)

        return header
Example #4
0
    def __init__(self):
        """
        """
        schema = {
            "required_columns":
            ("concept_header_id", "date_created", "description"),
            "default_column":
            "description"
        }

        super(DataVersion, self).__init__(key="data_version", schema=schema)

        self.default_version = self.get_unique_id(
            query=TableQuery("description == 'default'"))
Example #5
0
    def _operator_generator(self, expr):
        """

        Parameters
        ----------
        expr

        Returns
        -------

        """
        # get ids of rows in self.table where `expr` holds
        idx = self.table.filter(TableQuery(expr)).index

        # wrap ids in a TableQuery instance
        res = self.table.construct_query_by_id(idx)

        return res
Example #6
0
    def get_default(self, concept_header_id):
        """

        Parameters
        ----------
        concept_header_id

        Returns
        -------

        """
        # query (leave 'date_added' empty)
        query = TableQuery({
            "concept_header_id": concept_header_id,
            "description": "default"
        })

        res = self.get_unique_id(query)

        return res
Example #7
0
 def apply_fun(tup):
     tbl = Table(key=tup[0], schema=None)
     q = TableQuery(
         ("{} == %r" % tup[1]).format(tbl._default_column))
     temp_res = tbl.get_unique_id(q)
     return temp_res
Example #8
0
 def apply_fun(row):
     res = len(self.filter(TableQuery(row)))
     return res