def test_convert_units(self): a = tstoolbox.read("tests/data_gainesville_daily_precip.csv", target_units="in") b = tstoolbox.equation( "x1/25.4", input_ts="tests/data_gainesville_daily_precip.csv").astype( "float64") b.columns = ["ADaymet-prcp:in"] assert_frame_equal(a, b) a = tstoolbox.read("tests/data_gainesville_daily_precip.csv", target_units="km") b = tstoolbox.equation( "x1/(1000*1000)", input_ts="tests/data_gainesville_daily_precip.csv").astype( "float64") b.columns = ["ADaymet-prcp:km"] assert_frame_equal(a, b) with pytest.raises(ValueError) as e_info: _ = tstoolbox.read("tests/data_gainesville_daily_precip.csv", source_units="ft3/s") assert ( r" You specified 'source_units' as ft3/s, but column units are mm." in str(e_info.value)) with pytest.raises(ValueError) as e_info: _ = tstoolbox.read("tests/data_gainesville_daily_precip.csv", target_units="ft3/s")
def test_extract(self): wdmtoolbox.createnewwdm(self.wdmname, overwrite=True) wdmtoolbox.createnewdsn(self.wdmname, 101, tcode=5, base_year=1870) wdmtoolbox.csvtowdm(self.wdmname, 101, input_ts='tests/sunspot_area.csv') ret1 = wdmtoolbox.extract(self.wdmname, 101).astype('f') ret2 = wdmtoolbox.extract('{0},101'.format(self.wdmname)).astype('f') assert_frame_equal(ret1, ret2) ret3 = tstoolbox.read('tests/sunspot_area.csv').astype('f') ret1.columns = ['Area'] assert_frame_equal(ret1, ret3) ret4 = tstoolbox.read('tests/sunspot_area_with_missing.csv', dropna='no').astype('f') wdmtoolbox.createnewdsn(self.wdmname, 500, tcode=5, base_year=1870) wdmtoolbox.csvtowdm(self.wdmname, 500, input_ts='tests/sunspot_area_with_missing.csv') ret5 = wdmtoolbox.extract(self.wdmname, 500).astype('f') ret5.columns = ['Area'] assert_frame_equal(ret5, ret4)
def setUp(self): self.data_0_to_1 = tstoolbox.read( 'tests/data_sunspot_normalized_0_to_1.csv') self.data_10_to_20 = tstoolbox.read( 'tests/data_sunspot_normalized_10_to_20.csv') self.data_zscore = tstoolbox.read( 'tests/data_sunspot_normalized_zscore.csv') self.data_zscore = tsutils.memory_optimize(self.data_zscore) self.data_pct_rank = tstoolbox.read( 'tests/data_sunspot_normalized_pct_rank.csv') self.data_pct_rank = tsutils.memory_optimize(self.data_pct_rank)
def setUp(self): self.data_0_to_1 = tstoolbox.read( "tests/data_sunspot_normalized_0_to_1.csv") self.data_0_to_1.columns = ["Area::minmax"] self.data_10_to_20 = tstoolbox.read( "tests/data_sunspot_normalized_10_to_20.csv") self.data_10_to_20.columns = ["Area::minmax"] self.data_zscore = tstoolbox.read( "tests/data_sunspot_normalized_zscore.csv") self.data_zscore.columns = ["Area::zscore"] self.data_zscore = tsutils.memory_optimize(self.data_zscore) self.data_pct_rank = tstoolbox.read( "tests/data_sunspot_normalized_pct_rank.csv") self.data_pct_rank.columns = ["Area::pct_rank"] self.data_pct_rank = tsutils.memory_optimize(self.data_pct_rank)
def test_small_window_len(self): out = tstoolbox.filter("flat", input_ts="tests/data_sine.csv", window_len=2) out1 = tstoolbox.read("tests/data_sine.csv") out1.columns = ["Value::filter"] # NOp assert_frame_equal(out, out1)
def test_small_window_len(self): out = tstoolbox.filter('flat', input_ts='tests/data_sine.csv', window_len=2) out1 = tstoolbox.read('tests/data_sine.csv') out1.columns = ['Value_filter'] # NOp assert_frame_equal(out, out1)
def test_round_index_mulitple_direct(self): """Test round_index API for multiple columns - daily.""" out = tstoolbox.read( "tests/data_simple.csv,tests/data_simple.csv", append="columns", round_index="D", ) assert_frame_equal(out, self.round_index_multiple_direct)
def test_small_window_len(self): out = tstoolbox.filter('flat', input_ts='tests/data_sine.csv', window_len=2) out1 = tstoolbox.read('tests/data_sine.csv') out1.columns = ['Value::filter'] # NOp assert_frame_equal(out, out1)
def test_kde_time_multiple_traces(): ndf = tstoolbox.read(['tests/daily.csv', 'tests/02325000_flow.csv']) return tstoolbox.plot(type='kde_time', columns=[2, 3], clean=True, input_ts=ndf, ytitle='Flow', ofilename=None)
def setUp(self): self.ats = tstoolbox.read(os.path.join('tests', 'data_sine.csv')) self.ats.index.name = 'Datetime' self.ats.columns = ['Value'] self.flat_3 = self.ats.join( tstoolbox.read(os.path.join('tests', 'data_filter_flat.csv'))) self.hanning = self.ats.join( tstoolbox.read(os.path.join('tests', 'data_filter_hanning.csv'))) self.fft_lowpass = self.ats.join( tstoolbox.read(os.path.join('tests', 'data_filter_fft_lowpass.csv'))) self.fft_highpass = self.ats.copy() self.fft_highpass.columns = ['Value_filter'] self.fft_highpass = self.ats.join(self.fft_highpass)
def test_boxplot(): ndf = tstoolbox.read(['tests/02234500_65_65.csv', 'tests/02325000_flow.csv'], clean=True, append='combine') return tstoolbox.plot(input_ts=ndf, clean=True, columns=[2, 3], type='boxplot', ofilename=None)
def test_equation_cols_over_nine(self): """Test of using equation API with columns over 9.""" input_ts = tstoolbox.read('tests/data_multiple_cols.csv,' 'tests/data_multiple_cols.csv,' 'tests/data_multiple_cols.csv,' 'tests/data_multiple_cols.csv,' 'tests/data_multiple_cols.csv', append='columns') out = tstoolbox.equation('x10*10', input_ts=input_ts) self.maxDiff = None assert_frame_equal(out, self.equation_result)
def test_kde_time_multiple_traces(): plt.close("all") ndf = tstoolbox.read(["tests/daily.csv", "tests/02325000_flow.csv"]) return tstoolbox.plot( type="kde_time", columns=[2, 3], clean=True, input_ts=ndf, ytitle="Flow", ofilename=None, )
def setUp(self): self.ats = tstoolbox.read(os.path.join('tests', 'data_sine.csv')) self.ats.index.name = 'Datetime' self.ats.columns = ['Value'] self.flat_3 = self.ats.join(tstoolbox.read(os.path.join('tests', 'data_filter_flat.csv'))) self.flat_3.columns = ['Value', 'Value::filter'] self.hanning = self.ats.join(tstoolbox.read(os.path.join('tests', 'data_filter_hanning.csv'))) self.hanning.columns = ['Value', 'Value::filter'] self.fft_lowpass = self.ats.join(tstoolbox.read(os.path.join('tests', 'data_filter_fft_lowpass.csv'))) self.fft_lowpass.columns = ['Value', 'Value::filter'] self.fft_highpass = self.ats.copy() self.fft_highpass.columns = ['Value::filter'] self.fft_highpass = self.ats.join(self.fft_highpass)
def test_start_date(self): wdmtoolbox.createnewwdm(self.wdmname, overwrite=True) wdmtoolbox.createnewdsn(self.wdmname, 101, tcode=2, base_year=1970, tsstep=15) wdmtoolbox.csvtowdm(self.wdmname, 101, input_ts='tests/nwisiv_02246000.csv') ret1 = wdmtoolbox.extract(self.wdmname, 101, start_date='2014-02-21 16:00:00') ret3 = tstoolbox.read('tests/nwisiv_02246000.csv', start_date='2014-02-21 16:00:00').astype('float64') ret1.columns = ['02246000_iv_00060'] assert_frame_equal(ret1, ret3)
def test_boxplot(): plt.close("all") xdf = tstoolbox.read( ["tests/02234500_65_65.csv", "tests/02325000_flow.csv"], clean=True, append="combine", ) return tstoolbox.plot(input_ts=xdf, clean=True, columns=[2, 3], type="boxplot", ofilename=None)
def setUp(self): self.ats = tstoolbox.read(os.path.join("tests", "data_sine.csv")) self.ats.index.name = "Datetime" self.ats.columns = ["Value"] self.flat_3 = self.ats.join( tstoolbox.read(os.path.join("tests", "data_filter_flat.csv"))) self.flat_3.columns = ["Value", "Value::filter"] self.hanning = self.ats.join( tstoolbox.read(os.path.join("tests", "data_filter_hanning.csv"))) self.hanning.columns = ["Value", "Value::filter"] self.fft_lowpass = self.ats.join( tstoolbox.read(os.path.join("tests", "data_filter_fft_lowpass.csv"))) self.fft_lowpass.columns = ["Value", "Value::filter"] self.fft_highpass = self.ats.copy() self.fft_highpass.columns = ["Value::filter"] self.fft_highpass = self.ats.join(self.fft_highpass)
def test_start_date(self): wdmtoolbox.createnewwdm(self.wdmname, overwrite=True) wdmtoolbox.createnewdsn(self.wdmname, 101, tcode=2, base_year=1970, tsstep=15) wdmtoolbox.csvtowdm(self.wdmname, 101, input_ts="tests/nwisiv_02246000.csv") ret1 = wdmtoolbox.extract(self.wdmname, 101, start_date="2014-02-21 16:00:00") ret3 = tstoolbox.read( "tests/nwisiv_02246000.csv", start_date="2014-02-21 16:00:00" ).astype("float64") ret3.index = ret3.index.tz_localize(None) ret1.columns = ["02246000_iv_00060"] assert_frame_equal(ret1, ret3, check_index_type=False)
def test_tstep(self): wdmtoolbox.createnewwdm(self.wdmname, overwrite=True) wdmtoolbox.createnewdsn(self.wdmname, 101, tcode=2, base_year=1970, tsstep=15) wdmtoolbox.csvtowdm(self.wdmname, 101, input_ts='tests/nwisiv_02246000.csv') ret1 = wdmtoolbox.extract(self.wdmname, 101) ret2 = wdmtoolbox.extract('{0},101'.format(self.wdmname)) assert_frame_equal(ret1, ret2) ret3 = tstoolbox.read('tests/nwisiv_02246000.csv').astype('float64') ret1.columns = ['02246000_iv_00060'] assert_frame_equal(ret1, ret3)
def test_equation_cols_over_nine(self): """Test of using equation API with columns over 9.""" input_ts = tstoolbox.read( "tests/data_multiple_cols.csv," "tests/data_multiple_cols.csv," "tests/data_multiple_cols.csv," "tests/data_multiple_cols.csv," "tests/data_multiple_cols.csv", append="columns", ) out = tstoolbox.equation("x10*10", input_ts=input_ts) self.maxDiff = None assert_frame_equal(out, self.equation_result)
def test_equation_cols_over_nine(self): ''' Test of using equation API with columns over 9. ''' input_ts = tstoolbox.read( 'tests/data_multiple_cols.csv,' 'tests/data_multiple_cols.csv,' 'tests/data_multiple_cols.csv,' 'tests/data_multiple_cols.csv,' 'tests/data_multiple_cols.csv', append='columns') out = tstoolbox.equation('x10*10', input_ts=input_ts) self.maxDiff = None assert_frame_equal(out, self.equation_result)
def setUp(self): self.df = tstoolbox.read( ["tests/data_sunspot.csv", "tests/data_sunspot.csv"]) self.gof = [ ["Bias", 0.0], ["Root-mean-square Deviation (RMSD)", 0.0], ["Centered RMSD (CRMSD)", 0.0], ["Correlation coefficient (r)", 1.0], ["Skill score (Murphy)", 1.0], ["Nash-Sutcliffe Efficiency", 1.0], ["Common count observed and simulated", 1672], ["Count of NaNs", "", 0, 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)
def test_extract(self): wdmtoolbox.createnewwdm(self.wdmname, overwrite=True) wdmtoolbox.createnewdsn(self.wdmname, 101, tcode=5, base_year=1870) wdmtoolbox.csvtowdm(self.wdmname, 101, input_ts="tests/sunspot_area.csv") ret1 = wdmtoolbox.extract(self.wdmname, 101).astype("f") ret2 = wdmtoolbox.extract("{0},101".format(self.wdmname)).astype("f") assert_frame_equal(ret1, ret2) ret3 = tstoolbox.read("tests/sunspot_area.csv").astype("f") ret1.columns = ["Area"] assert_frame_equal(ret1, ret3) ret4 = tstoolbox.read( "tests/sunspot_area_with_missing.csv", dropna="no" ).astype("f") wdmtoolbox.createnewdsn(self.wdmname, 500, tcode=5, base_year=1870) wdmtoolbox.csvtowdm( self.wdmname, 500, input_ts="tests/sunspot_area_with_missing.csv" ) ret5 = wdmtoolbox.extract(self.wdmname, 500).astype("f") ret5.columns = ["Area"] assert_frame_equal(ret5, ret4)
def test_copy_to_self(self): wdmtoolbox.createnewwdm(self.wdmname, overwrite=True) wdmtoolbox.createnewdsn(self.wdmname, 101, tcode=2, base_year=1970, tsstep=15) wdmtoolbox.csvtowdm(self.wdmname, 101, input_ts='tests/nwisiv_02246000.csv') ret1 = wdmtoolbox.extract(self.wdmname, 101) ret2 = wdmtoolbox.extract('{0},101'.format(self.wdmname)) assert_frame_equal(ret1, ret2) ret3 = tstoolbox.read('tests/nwisiv_02246000.csv').astype('float64') ret1.columns = ['02246000_iv_00060'] assert_frame_equal(ret1, ret3) wdmtoolbox.copydsn(self.wdmname, 101, self.wdmname, 1101)
def test_extract(self): wdmtoolbox.createnewwdm(self.wdmname, overwrite=True) wdmtoolbox.createnewdsn(self.wdmname, 101, tcode=5, base_year=1870) wdmtoolbox.csvtowdm(self.wdmname, 101, input_ts='tests/sunspot_area.csv') ret1 = wdmtoolbox.extract(self.wdmname, 101) ret2 = wdmtoolbox.extract('{0},101'.format(self.wdmname)) assert_frame_equal(ret1, ret2) ret3 = tstoolbox.read('tests/sunspot_area.csv') ret1.columns = ['Area'] assert_frame_equal(ret1, ret3) ret4 = tstoolbox.read('tests/sunspot_area_with_missing.csv', dropna='no') wdmtoolbox.createnewdsn(self.wdmname, 500, tcode=5, base_year=1870) wdmtoolbox.csvtowdm(self.wdmname, 500, input_ts='tests/sunspot_area_with_missing.csv') ret5 = wdmtoolbox.extract(self.wdmname, 500) ret5.columns = ['Area'] assert_frame_equal(ret5, ret4)
def test_end_date(self): wdmtoolbox.createnewwdm(self.wdmname, overwrite=True) wdmtoolbox.createnewdsn(self.wdmname, 101, tcode=2, base_year=1970, tsstep=15) wdmtoolbox.csvtowdm(self.wdmname, 101, input_ts='tests/nwisiv_02246000.csv') ret1 = wdmtoolbox.extract(self.wdmname, 101, end_date='2014-02-22 11:00:00') ret3 = tstoolbox.read('tests/nwisiv_02246000.csv', end_date='2014-02-22 11:00:00').astype('float64') ret3.index = ret3.index.tz_localize(None) ret1.columns = ['02246000_iv_00060'] assert_frame_equal(ret1, ret3, check_index_type=False)
def test_end_date(self): wdmtoolbox.createnewwdm(self.wdmname, overwrite=True) wdmtoolbox.createnewdsn(self.wdmname, 101, tcode=2, base_year=1970, tsstep=15) wdmtoolbox.csvtowdm(self.wdmname, 101, input_ts='tests/nwisiv_02246000.csv') ret1 = wdmtoolbox.extract(self.wdmname, 101, end_date='2014-02-22 11:00:00') ret3 = tstoolbox.read('tests/nwisiv_02246000.csv', end_date='2014-02-22 11:00:00').astype('float64') ret1.columns = ['02246000_iv_00060'] assert_frame_equal(ret1, ret3)
def test_copy_to_self(self): wdmtoolbox.createnewwdm(self.wdmname, overwrite=True) wdmtoolbox.createnewdsn(self.wdmname, 101, tcode=2, base_year=1970, tsstep=15) wdmtoolbox.csvtowdm(self.wdmname, 101, input_ts="tests/nwisiv_02246000.csv") ret1 = wdmtoolbox.extract(self.wdmname, 101) ret2 = wdmtoolbox.extract("{0},101".format(self.wdmname)) assert_frame_equal(ret1, ret2, check_index_type=False) ret3 = tstoolbox.read("tests/nwisiv_02246000.csv").astype("float64") ret3.index = ret3.index.tz_localize(None) ret1.columns = ["02246000_iv_00060"] assert_frame_equal(ret1, ret3, check_index_type=False) wdmtoolbox.copydsn(self.wdmname, 101, self.wdmname, 1101)
def setUp(self): """Prepare in-memory versions of the files ./data_flat.csv.""" self.fdata = tstoolbox.read("tests/data_flat.csv,tests/data_sunspot.csv") self.fdata.index.name = "Datetime"
def test_createts_from_input(self): """Create a ts of data_flat.csv.""" out = tstoolbox.createts(input_ts=self.data).index out1 = tstoolbox.read('tests/data_flat.csv').index assert_index_equal(out, out1)
def test_read_direct_dropna(self): """Test read dropna for single column - daily.""" out = tstoolbox.read('tests/data_missing.csv', dropna='all') assert_frame_equal(out, self.read_direct)
def test_ts_intervals(self): """Test many intervals to make sure tstoolbox makes a good guess.""" # 'matches' lists out things that should match but tstoolbox will give # the simpler answer. For example 4 quarters is equal to a 1 year # interval. Also difficult for tstoolbox to figure out that a 2 month # interval isn't a 1 month interval with gaps. matches = { '4Q': '1A', '8Q': '2A', '4BQS': '1BAS', '8BQS': '2BAS', '4BQ': '1BA', '8BQ': '2BA', '4QS': '1AS', '8QS': '2AS', # '2M': '1M', '3M': '1Q', # '4M': '1M', # '5M': '1M', '6M': '2Q', # '7M': '1M', # '8M': '1M', '9M': '3Q', # '10M': '1M', # '11M': '1M', # '2BMS': '1BMS', '3BMS': '1BQS', # '4BMS': '1BMS', # '5BMS': '1BMS', '6BMS': '2BQS', # '7BMS': '1BMS', # '8BMS': '1BMS', '9BMS': '3BQS', # '10BMS': '1BMS', # '11BMS': '1BMS', # '2BM': '1BM', '3BM': '1BQ', # '4BM': '1BM', # '5BM': '1BM', '6BM': '2BQ', # '7BM': '1BM', # '8BM': '1BM', '9BM': '3BQ', # '10BM': '1BM', # '11BM': '1BM', # '2MS': '1MS', '3MS': '1QS', # '4MS': '1MS', # '5MS': '1MS', '6MS': '2QS', # '7MS': '1MS', # '8MS': '1MS', '9MS': '3QS', # '10MS': '1MS', # '11MS': '1MS', '5B': '1W', '7D': '1W', # BUG!!! '2B': '2D', '3B': '1D', '4B': '2D', '6B': '2D', '7B': '1D', '8B': '2D', '9B': '1D', } for key in self.fps: df = tstoolbox.read(self.fps[key][1]) inferred_code = df.index.inferred_freq if inferred_code is None: continue testcode = '{0}{1}'.format(*key) if inferred_code[0] not in '123456789': inferred_code = '1' + inferred_code if testcode in matches: testcode = matches[testcode] try: self.assertEqual(testcode, inferred_code.split('-')[0]) except AssertionError: self.assertEqual([i for i in testcode if not i.isdigit()], [i for i in inferred_code.split('-')[0] if not i.isdigit()])
def setUp(self): self.disaggregate_temperature = tstoolbox.read( "tests/data_temperature_gainesville_disaggregate_sine_mean.csv")
def test_read_bi_monthly(self): """Test read API for bi monthly time series.""" out = tstoolbox.read("tests/data_bi_daily.csv") assert_frame_equal(out, self.read_tsstep_2_daily)
def test_read_mulitple_direct_list(self): """Test read API for multiple columns - daily.""" out = tstoolbox.read( ["tests/data_simple.csv", "tests/data_simple.csv"], append=r"columns") assert_frame_equal(out, self.read_multiple_direct)
def test_read_direct(self): """Test read API for single column - daily.""" out = tstoolbox.read("tests/data_simple.csv") assert_frame_equal(out, self.read_direct)
def test_createts_from_input(self): """Create a ts of data_flat.csv.""" out = tstoolbox.createts(input_ts=self.data).index out1 = tstoolbox.read("tests/data_flat.csv").index assert_index_equal(out, out1)
def setUp(self): self.ats = tstoolbox.read(os.path.join('tests', 'data_sine.csv')) self.ats.index.name = 'Datetime' self.ats.columns = ['Value::clip'] self.ats.loc[self.ats['Value::clip'] < -0.75, 'Value::clip'] = -0.75 self.ats.loc[self.ats['Value::clip'] > 0.75, 'Value::clip'] = 0.75
def test_round_index_mulitple_direct(self): """Test round_index API for multiple columns - daily.""" out = tstoolbox.read('tests/data_simple.csv,tests/data_simple.csv', append='columns', round_index='D') assert_frame_equal(out, self.round_index_multiple_direct)
def test_read_direct_sparse(self): """Test read API for single column - daily.""" out = tstoolbox.read('tests/data_simple_extra_rows_sparse.csv', skiprows=[4, 6]) assert_frame_equal(out, self.read_direct_sparse)
def test_read_direct_sparse(self): """Test read API for single column - daily.""" out = tstoolbox.read("tests/data_simple_extra_rows_sparse.csv", skiprows=[4, 6]) assert_frame_equal(out, self.read_direct_sparse)
def test_round_index_bi_monthly(self): """Test round_index API for bi monthly time series.""" out = tstoolbox.read('tests/data_bi_daily.csv', round_index='D') assert_frame_equal(out, self.round_index_tsstep_2_daily)
def setUp(self): self.ats = tstoolbox.read(os.path.join("tests", "data_sine.csv")) self.ats.index.name = "Datetime" self.ats.columns = ["Value::clip"] self.ats.loc[self.ats["Value::clip"] < -0.75, "Value::clip"] = -0.75 self.ats.loc[self.ats["Value::clip"] > 0.75, "Value::clip"] = 0.75
def test_ts_intervals(self): ''' Test many intervals to make sure tstoolbox makes a good guess. ''' # 'matches' lists out things that should match but tstoolbox will give # the simpler answer. For example 4 quarters is equal to a 1 year # interval. Also difficult for tstoolbox to figure out that a 2 month # interval isn't a 1 month interval with gaps. matches = { '4Q': '1A', '8Q': '2A', '4BQS': '1BAS', '8BQS': '2BAS', '4BQ': '1BA', '8BQ': '2BA', '4QS': '1AS', '8QS': '2AS', #'2M': '1M', '3M': '1Q', #'4M': '1M', #'5M': '1M', '6M': '2Q', #'7M': '1M', #'8M': '1M', '9M': '3Q', #'10M': '1M', #'11M': '1M', #'2BMS': '1BMS', '3BMS': '1BQS', #'4BMS': '1BMS', #'5BMS': '1BMS', '6BMS': '2BQS', #'7BMS': '1BMS', #'8BMS': '1BMS', '9BMS': '3BQS', #'10BMS': '1BMS', #'11BMS': '1BMS', #'2BM': '1BM', '3BM': '1BQ', #'4BM': '1BM', #'5BM': '1BM', '6BM': '2BQ', #'7BM': '1BM', #'8BM': '1BM', '9BM': '3BQ', #'10BM': '1BM', #'11BM': '1BM', #'2MS': '1MS', '3MS': '1QS', #'4MS': '1MS', #'5MS': '1MS', '6MS': '2QS', #'7MS': '1MS', #'8MS': '1MS', '9MS': '3QS', #'10MS': '1MS', #'11MS': '1MS', '5B': '1W', '7D': '1W', #BUG!!! '2B': '2D', '3B': '1D', '4B': '2D', '6B': '2D', '7B': '1D', '8B': '2D', '9B': '1D', } for key in self.fps: df = tstoolbox.read(self.fps[key][1]) inferred_code = df.index.inferred_freq if inferred_code is None: continue testcode = '{0}{1}'.format(*key) if inferred_code[0] not in '123456789': inferred_code = '1' + inferred_code if testcode in matches: testcode = matches[testcode] try: self.assertEqual(testcode, inferred_code.split('-')[0]) except AssertionError: self.assertEqual([i for i in testcode if not i.isdigit()], [ i for i in inferred_code.split('-')[0] if not i.isdigit() ])
def test_ts_intervals(self): """Test many intervals to make sure tstoolbox makes a good guess.""" # 'matches' lists out things that should match but tstoolbox will give # the simpler answer. For example 4 quarters is equal to a 1 year # interval. Also difficult for tstoolbox to figure out that a 2 month # interval isn't a 1 month interval with gaps. matches = { "4Q": "1A", "8Q": "2A", "4BQS": "1BAS", "8BQS": "2BAS", "4BQ": "1BA", "8BQ": "2BA", "4QS": "1AS", "8QS": "2AS", # '2M': '1M', "3M": "1Q", # '4M': '1M', # '5M': '1M', "6M": "2Q", # '7M': '1M', # '8M': '1M', "9M": "3Q", # '10M': '1M', # '11M': '1M', # '2BMS': '1BMS', "3BMS": "1BQS", # '4BMS': '1BMS', # '5BMS': '1BMS', "6BMS": "2BQS", # '7BMS': '1BMS', # '8BMS': '1BMS', "9BMS": "3BQS", # '10BMS': '1BMS', # '11BMS': '1BMS', # '2BM': '1BM', "3BM": "1BQ", # '4BM': '1BM', # '5BM': '1BM', "6BM": "2BQ", # '7BM': '1BM', # '8BM': '1BM', "9BM": "3BQ", # '10BM': '1BM', # '11BM': '1BM', # '2MS': '1MS', "3MS": "1QS", # '4MS': '1MS', # '5MS': '1MS', "6MS": "2QS", # '7MS': '1MS', # '8MS': '1MS', "9MS": "3QS", # '10MS': '1MS', # '11MS': '1MS', "5B": "1W", "7D": "1W", # BUG!!! "2B": "2D", "3B": "1D", "4B": "2D", "6B": "2D", "7B": "1D", "8B": "2D", "9B": "1D", } for key in self.fps: df = tstoolbox.read(self.fps[key][1]) inferred_code = df.index.inferred_freq if inferred_code is None: continue testcode = "{0}{1}".format(*key) if inferred_code[0] not in "123456789": inferred_code = "1" + inferred_code if testcode in matches: testcode = matches[testcode] try: self.assertEqual(testcode, inferred_code.split("-")[0]) except AssertionError: self.assertEqual( [i for i in testcode if not i.isdigit()], [ i for i in inferred_code.split("-")[0] if not i.isdigit() ], )
def test_round_index_direct(self): """Test round_index API for single column - daily.""" out = tstoolbox.read('tests/data_simple.csv', round_index='D') assert_frame_equal(out, self.round_index_direct)