Example #1
0
    def test_copy(self):
        df = pd.DataFrame(index=t_date_range,
                          data={
                              'rx': rx_list,
                              'tx': tx_list
                          })
        cml_ch = ComlinkChannel(data=df, frequency=f)
        cml_ch_copy = cml_ch.copy()

        assert (type(cml_ch_copy) == ComlinkChannel)

        # Test (at least one) metadata attribute
        assert (cml_ch_copy.f_GHz == cml_ch.f_GHz)

        # Test that DataFrames are equal
        pd.util.testing.assert_frame_equal(cml_ch_copy.data, cml_ch.data)

        # Test that the new DataFrame is a copy and not a view
        cml_ch.data.rx[1] = -9999
        assert (cml_ch.rx[1] != cml_ch_copy.rx[1])

        # Test that the new metadata is not a reference but a copy
        cml_ch.f_GHz = 999
        assert (cml_ch.f_GHz == 999)
        assert (cml_ch_copy.f_GHz == f / 1e9)
Example #2
0
    def test_resampling(self):
        df = pd.DataFrame(index=t_date_range, data={"rx": rx_list, "tx": tx_list})
        cml_ch_1min = ComlinkChannel(data=df, frequency=f)
        cml_ch_5min = ComlinkChannel(
            data=df.resample("5min").apply(np.mean), frequency=f
        )

        cml_ch_5min_no_inplace_kwarg = cml_ch_1min.resample("5min")
        assert type(cml_ch_5min_no_inplace_kwarg) == ComlinkChannel
        assert_comlink_channel_equal(cml_ch_5min_no_inplace_kwarg, cml_ch_5min)

        cml_ch_5min_inplace_false = cml_ch_1min.resample("5min", inplace=False)
        assert type(cml_ch_5min_inplace_false) == ComlinkChannel
        assert_comlink_channel_equal(cml_ch_5min_inplace_false, cml_ch_5min)

        cml_ch_5min_inplace_true = cml_ch_1min.copy()
        cml_ch_5min_inplace_true.resample("5min", inplace=True)
        assert type(cml_ch_5min_inplace_true) == ComlinkChannel
        assert_comlink_channel_equal(cml_ch_5min_inplace_true, cml_ch_5min)