예제 #1
0
 def test_fill_linear(self):
     ''' Test linear interpolation fill API.
     '''
     out = tstoolbox.fill(method='linear',
                          input_ts='tests/data_missing.csv')
     self.maxDiff = None
     assert_frame_equal(out, self.linear_compare)
예제 #2
0
 def test_fill_nearest(self):
     ''' Test nearest fill API.
     '''
     out = tstoolbox.fill(method='nearest',
                          input_ts='tests/data_missing.csv')
     self.maxDiff = None
     assert_frame_equal(out, self.nearest_compare)
예제 #3
0
 def test_fill_median(self):
     ''' Test fill with median API.
     '''
     out = tstoolbox.fill(method='median',
                          input_ts='tests/data_missing.csv')
     self.maxDiff = None
     assert_frame_equal(out, self.median_compare)
예제 #4
0
 def test_fill_from(self):
     """Test fill with from API."""
     out = tstoolbox.fill(
         method="from",
         input_ts="tests/data_fill_from.csv",
         from_columns=[2, 3],
         to_columns=1,
     )
     compare = tstoolbox.read("tests/data_fill_from.csv")
     compare.columns = ["Value::fill", "Value1::fill", "Value2::fill"]
     compare.loc["2000-01-02", "Value::fill"] = 2.5
     compare.loc["2000-01-04", "Value::fill"] = 23.1
     self.conDiff = None
     assert_frame_equal(out, compare)
예제 #5
0
def load_aqi():

    #load raw data
    df15 = iter_dir('./2015')
    df16 = iter_dir('./2016')
    df = pd.concat([df15, df16])

    #just select AQI for now
    aqi = df[df['type'] == 'AQI']

    #parse into datetime
    aqi['datetime'] = aqi.apply(lambda x: parse_date(x), axis=1)

    #fill in missing entries with NaN
    aqi = aqi.set_index('datetime').resample('H').asfreq()

    #linearly interpolate missing entries
    imputed_data = fill(method='linear', input_ts=aqi)

    return imputed_data
예제 #6
0
 def test_fill_nearest(self):
     """Test nearest fill API."""
     out = tstoolbox.fill(method="nearest",
                          input_ts="tests/data_missing.csv")
     self.maxDiff = None
     assert_frame_equal(out, self.nearest_compare)
예제 #7
0
 def test_fill_linear(self):
     """Test linear interpolation fill API."""
     out = tstoolbox.fill(method="linear",
                          input_ts="tests/data_missing.csv")
     self.maxDiff = None
     assert_frame_equal(out, self.linear_compare)
예제 #8
0
 def test_fill_bfill(self):
     """Test backward fill API."""
     out = tstoolbox.fill(method="bfill", input_ts="tests/data_missing.csv")
     self.maxDiff = None
     assert_frame_equal(out, self.bfill_compare)
예제 #9
0
 def test_fill_ffill_direct(self):
     """Test forward fill API."""
     out = tstoolbox.fill(input_ts="tests/data_missing.csv")
     self.maxDiff = None
     assert_frame_equal(out, self.ffill_compare)
예제 #10
0
 def test_fill_value(self):
     ''' Test fill with value API.
     '''
     with assert_raises_regexp(ValueError,
                               r"The allowable values for 'method' are"):
         out = tstoolbox.fill(method='a', input_ts='tests/data_missing.csv')
예제 #11
0
 def test_fill_bfill(self):
     """Test backward fill API."""
     out = tstoolbox.fill(method='bfill',
                          input_ts='tests/data_missing.csv')
     self.maxDiff = None
     assert_frame_equal(out, self.bfill_compare)
예제 #12
0
 def test_fill_bfill(self):
     ''' Test backward fill API.
     '''
     out = tstoolbox.fill(method='bfill', input_ts='tests/data_missing.csv')
     self.maxDiff = None
     assert_frame_equal(out, self.bfill_compare)
예제 #13
0
 def test_fill_value(self):
     """Test fill with value API."""
     with pytest.raises(ValueError) as e_info:
         _ = tstoolbox.fill(method='a',
                            input_ts='tests/data_missing.csv')
     assert r"The allowable values for 'method' are" in str(e_info.value)
예제 #14
0
 def test_fill_con(self):
     """Test fill with con API."""
     out = tstoolbox.fill(method=2.42,
                          input_ts='tests/data_missing.csv')
     self.conDiff = None
     assert_frame_equal(out, self.con_compare)
예제 #15
0
 def test_fill_max(self):
     """Test fill with max API."""
     out = tstoolbox.fill(method='max',
                          input_ts='tests/data_missing.csv')
     self.maxDiff = None
     assert_frame_equal(out, self.max_compare)
예제 #16
0
 def test_fill_nearest(self):
     """Test nearest fill API."""
     out = tstoolbox.fill(method='nearest',
                          input_ts='tests/data_missing.csv')
     self.maxDiff = None
     assert_frame_equal(out, self.nearest_compare)
예제 #17
0
 def test_fill_linear(self):
     """Test linear interpolation fill API."""
     out = tstoolbox.fill(method='linear',
                          input_ts='tests/data_missing.csv')
     self.maxDiff = None
     assert_frame_equal(out, self.linear_compare)
예제 #18
0
 def test_fill_max(self):
     """Test fill with max API."""
     out = tstoolbox.fill(method="max", input_ts="tests/data_missing.csv")
     self.maxDiff = None
     assert_frame_equal(out, self.max_compare)
예제 #19
0
 def test_fill_con(self):
     """Test fill with con API."""
     out = tstoolbox.fill(method=2.42, input_ts="tests/data_missing.csv")
     self.conDiff = None
     assert_frame_equal(out, self.con_compare)
예제 #20
0
 def test_fill_ffill_direct(self):
     """Test forward fill API."""
     out = tstoolbox.fill(input_ts='tests/data_missing.csv')
     self.maxDiff = None
     assert_frame_equal(out, self.ffill_compare)
예제 #21
0
 def test_fill_value(self):
     """Test fill with value API."""
     with pytest.raises(ValueError) as e_info:
         _ = tstoolbox.fill(method="a", input_ts="tests/data_missing.csv")
     assert r'The argument "method" should be one of the terms in' in str(
         e_info.value)
예제 #22
0
 def test_fill_value(self):
     """Test fill with value API."""
     with pytest.raises(ValueError) as e_info:
         _ = tstoolbox.fill(method="a", input_ts="tests/data_missing.csv")
     assert r"The allowable values for 'method' are" in str(e_info.value)