Ejemplo n.º 1
0
def test_subsetnumeric_subsetnumeric(get_dataframe):
    """
    This test applies two numeric subsets one
    after the other
    """

    sub_cola = "shape_star"
    sub_lowa = 0.1
    sub_higha = 0.2
    sub_colb = "shape_leng"
    sub_lowb = 1.0
    sub_highb = 2.0
    t = Table("geography.admin3")
    t_df = get_dataframe(t)

    sub_q = t.numeric_subset(sub_cola, sub_lowa,
                             sub_lowb).numeric_subset(sub_colb, sub_lowb,
                                                      sub_highb)
    sub_df = t_df[(sub_lowa <= t_df[sub_cola])
                  & (t_df[sub_cola] <= sub_higha)
                  & (sub_lowb <= t_df[sub_colb])
                  & (t_df[sub_colb] <= sub_highb)]
    sub_df = sub_df.reset_index(drop=True)

    assert get_dataframe(sub_q).equals(sub_df)
Ejemplo n.º 2
0
def test_subset_subsetnumeric(get_dataframe):
    """
    This test applies a non-numeric subsets and
    a numeric subset one after another in both possible
    orders.
    """

    sub_cola = "admin1name"
    sub_vala = "Central Development Region"
    sub_colb = "shape_area"
    sub_lowb = 0.1
    sub_highb = 0.12
    t = Table("geography.admin3")
    t_df = get_dataframe(t)

    sub_q1 = t.subset(sub_cola,
                      sub_vala).numeric_subset(sub_colb, sub_lowb, sub_highb)
    sub_q2 = t.numeric_subset(sub_colb, sub_lowb,
                              sub_highb).subset(sub_cola, sub_vala)
    sub_df = t_df[(t_df[sub_cola] == sub_vala)
                  & (sub_lowb <= t_df[sub_colb])
                  & (t_df[sub_colb] <= sub_highb)]
    sub_df = sub_df.reset_index(drop=True)

    assert get_dataframe(sub_q1).equals(sub_df)
    assert get_dataframe(sub_q2).equals(sub_df)
Ejemplo n.º 3
0
class TestSubsetOfSubset(TestCase):
    def setUp(self):

        self.t = Table("geography.admin3")
        self.t_df = self.t.get_dataframe()

    def test_subset_subset(self):
        """
        This test applies two non-numeric subsets one
        after the other .
        """

        sub_cola = "admin1name"
        sub_vala = "Central Development Region"
        sub_colb = "admin2name"
        sub_valb = "Bagmati"

        sub_q = self.t.subset(sub_cola, sub_vala).subset(sub_colb, sub_valb)
        sub_df = self.t_df[(self.t_df[sub_cola] == sub_vala)
                           & (self.t_df[sub_colb] == sub_valb)]
        sub_df = sub_df.reset_index(drop=True)

        self.assertTrue(sub_q.get_dataframe().equals(sub_df))

    def test_subset_subsetnumeric(self):
        """
        This test applies a non-numeric subsets and 
        a numeric subset one after another in both possible
        orders.
        """

        sub_cola = "admin1name"
        sub_vala = "Central Development Region"
        sub_colb = "shape_area"
        sub_lowb = 0.1
        sub_highb = 0.12

        sub_q1 = self.t.subset(sub_cola, sub_vala).numeric_subset(
            sub_colb, sub_lowb, sub_highb)
        sub_q2 = self.t.numeric_subset(sub_colb, sub_lowb,
                                       sub_highb).subset(sub_cola, sub_vala)
        sub_df = self.t_df[(self.t_df[sub_cola] == sub_vala)
                           & (sub_lowb <= self.t_df[sub_colb])
                           & (self.t_df[sub_colb] <= sub_highb)]
        sub_df = sub_df.reset_index(drop=True)

        self.assertTrue(sub_q1.get_dataframe().equals(sub_df))
        self.assertTrue(sub_q2.get_dataframe().equals(sub_df))

    def test_subsetnumeric_subsetnumeric(self):
        """
        This test applies two numeric subsets one
        after the other 
        """

        sub_cola = "shape_star"
        sub_lowa = 0.1
        sub_higha = 0.2
        sub_colb = "shape_leng"
        sub_lowb = 1.0
        sub_highb = 2.0

        sub_q = self.t.numeric_subset(sub_cola, sub_lowa,
                                      sub_lowb).numeric_subset(
                                          sub_colb, sub_lowb, sub_highb)
        sub_df = self.t_df[(sub_lowa <= self.t_df[sub_cola])
                           & (self.t_df[sub_cola] <= sub_higha)
                           & (sub_lowb <= self.t_df[sub_colb])
                           & (self.t_df[sub_colb] <= sub_highb)]
        sub_df = sub_df.reset_index(drop=True)

        self.assertTrue(sub_q.get_dataframe().equals(sub_df))