def test_df_equal(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")

        exp1 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=4, i=1),
             dict(k1="b", k2="b", v=1, i=2)])
        exp2 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=4, i=1),
             dict(k1="b", k2="b", v=1, i=2)])
        assert df_equal(exp1, exp2)

        exp1 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=4, i=1),
             dict(k1="b", k2="b", v=1, i=2)])
        exp2 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=4, i=1),
             dict(k1="b", k2="b", v=1, i=2)])
        exp2 = exp2[["k2", "k1", "v", "i"]]
        assert df_equal(exp1, exp2)

        exp1 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=4, i=1),
             dict(k1="b", k2="b", v=1, i=2)])
        exp2 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=3, i=1),
             dict(k1="b", k2="b", v=1, i=2)])
        assert not df_equal(exp1, exp2)

        exp1 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=4, i=1),
             dict(k1="b", k2="b", v=1, i=2)])
        exp2 = pandas.DataFrame([
            dict(k1="a", k2="b", v=numpy.nan, i=1),
            dict(k1="b", k2="b", v=1, i=2)
        ])
        assert not df_equal(exp1, exp2)

        exp1 = pandas.DataFrame([
            dict(k1="a", k2="b", v=numpy.nan, i=1),
            dict(k1="b", k2="b", v=1, i=2)
        ])
        exp2 = pandas.DataFrame([
            dict(k1="a", k2="b", v=numpy.nan, i=1),
            dict(k1="b", k2="b", v=1, i=2)
        ])
        assert not df_equal(exp1, exp2)
    def test_groupby_sort_head(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        l = [dict(k1="a", k2="b", v=4, i=1),
             dict(k1="a", k2="b", v=5, i=1),
             dict(k1="a", k2="b", v=4, i=2),
             dict(k1="b", k2="b", v=1, i=2),
             dict(k1="b", k2="b", v=1, i=3),
             ]

        exp = [dict(k1="a", k2="b", v=4, i=1),
               dict(k1="b", k2="b", v=1, i=2),
               ]

        df = pandas.DataFrame(l)
        exp = pandas.DataFrame(exp)

        res = groupby_topn(df, by_keys=["k1", "k2"],
                           sort_keys=["v", "i"], as_index=False)
        b = df_equal(exp, res)
        if not b:
            raise Exception(
                "dataframe not equal\nRES:\n{0}\nEXP\n{1}".format(str(res), str(exp)))
    def test_groupby_sort_head(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")

        ld = [
            dict(k1="a", k2="b", v=4, i=1),
            dict(k1="a", k2="b", v=5, i=1),
            dict(k1="a", k2="b", v=4, i=2),
            dict(k1="b", k2="b", v=1, i=2),
            dict(k1="b", k2="b", v=1, i=3)
        ]

        exp = [dict(k1="a", k2="b", v=4, i=1), dict(k1="b", k2="b", v=1, i=2)]

        df = pandas.DataFrame(ld)
        exp = pandas.DataFrame(exp)

        res = groupby_topn(df,
                           by_keys=["k1", "k2"],
                           sort_keys=["v", "i"],
                           as_index=False)
        b = df_equal(exp, res)
        if not b:
            raise Exception("dataframe not equal\nRES:\n{0}\nEXP\n{1}".format(
                str(res), str(exp)))
Beispiel #4
0
    def test_faq_pandas(self):
        fLOG(__file__,
             self._testMethodName,
             OutputPrint=__name__ == "__main__")

        df = pandas.DataFrame([{"a": 1}])
        if False:
            # does not work
            df_to_clipboard(df)
        assert df_equal(df, df)
        speed_dataframe()
Beispiel #5
0
    def test_faq_pandas(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        df = pandas.DataFrame([{"a": 1}])
        if False:
            # does not work
            df_to_clipboard(df)
        assert df_equal(df, df)
        speed_dataframe()
Beispiel #6
0
    def test_df_equal(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        exp1 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=4, i=1), dict(k1="b", k2="b", v=1, i=2)])
        exp2 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=4, i=1), dict(k1="b", k2="b", v=1, i=2)])
        assert df_equal(exp1, exp2)

        exp1 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=4, i=1), dict(k1="b", k2="b", v=1, i=2)])
        exp2 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=4, i=1), dict(k1="b", k2="b", v=1, i=2)])
        exp2 = exp2[["k2", "k1", "v", "i"]]
        assert df_equal(exp1, exp2)

        exp1 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=4, i=1), dict(k1="b", k2="b", v=1, i=2)])
        exp2 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=3, i=1), dict(k1="b", k2="b", v=1, i=2)])
        assert not df_equal(exp1, exp2)

        exp1 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=4, i=1), dict(k1="b", k2="b", v=1, i=2)])
        exp2 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=numpy.nan, i=1), dict(k1="b", k2="b", v=1, i=2)])
        assert not df_equal(exp1, exp2)

        exp1 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=numpy.nan, i=1), dict(k1="b", k2="b", v=1, i=2)])
        exp2 = pandas.DataFrame(
            [dict(k1="a", k2="b", v=numpy.nan, i=1), dict(k1="b", k2="b", v=1, i=2)])
        assert not df_equal(exp1, exp2)