# HG changeset patch # User Aurélien Campéas # Date 1718292399 -7200 # Thu Jun 13 17:26:39 2024 +0200 # Node ID 97bc4fc967dae0baf9be7b1802fe15a9a585055b # Parent e463a8163d0f0940aafd07652e72ca294b6ecb97 reduce the number of deprecation warnings diff --git a/test/test_api.py b/test/test_api.py --- a/test/test_api.py +++ b/test/test_api.py @@ -172,7 +172,7 @@ def test_manual_overrides(tsx): # start testing manual overrides - ts_begin = genserie(datetime(2010, 1, 1), 'D', 5, [2.]) + ts_begin = genserie(datetime(2010, 1, 1), 'd', 5, [2.]) ts_begin.loc['2010-01-04'] = -1 tsx.update('ts_mixte', ts_begin, 'test') @@ -190,7 +190,7 @@ assert not marker.any() # refresh all the period + 1 extra data point - ts_more = genserie(datetime(2010, 1, 2), 'D', 5, [2]) + ts_more = genserie(datetime(2010, 1, 2), 'd', 5, [2]) ts_more.loc['2010-01-04'] = -1 tsx.update('ts_mixte', ts_more, 'test') @@ -205,7 +205,7 @@ # just append an extra data point # with no intersection with the previous ts - ts_one_more = genserie(datetime(2010, 1, 7), 'D', 1, [2]) + ts_one_more = genserie(datetime(2010, 1, 7), 'd', 1, [2]) tsx.update('ts_mixte', ts_one_more, 'test') assert_df(""" @@ -222,7 +222,7 @@ # edit the bogus upstream data: -1 -> 3 # also edit the next value - ts_manual = genserie(datetime(2010, 1, 4), 'D', 2, [3]) + ts_manual = genserie(datetime(2010, 1, 4), 'd', 2, [3]) tsx.update('ts_mixte', ts_manual, 'test', manual=True) assert tsx.supervision_status('ts_mixte') == 'supervised' @@ -279,7 +279,7 @@ """, ts) # another iterleaved editing session - ts_edit = genserie(datetime(2010, 1, 4), 'D', 1, [2]) + ts_edit = genserie(datetime(2010, 1, 4), 'd', 1, [2]) tsx.update('ts_mixte', ts_edit, 'test', manual=True) assert 2 == tsx.get('ts_mixte')['2010-01-04'] # still ts, marker = tsx.edited('ts_mixte') @@ -324,10 +324,10 @@ 2010-01-07 2.0 """, ts_auto) - ts_manual = genserie(datetime(2010, 1, 5), 'D', 2, [3]) + ts_manual = genserie(datetime(2010, 1, 5), 'd', 2, [3]) tsx.update('ts_mixte', ts_manual, 'test', manual=True) - ts_manual = genserie(datetime(2010, 1, 9), 'D', 1, [3]) + ts_manual = genserie(datetime(2010, 1, 9), 'd', 1, [3]) tsx.update('ts_mixte', ts_manual, 'test', manual=True) tsx.update('ts_mixte', ts_auto, 'test') @@ -378,7 +378,7 @@ for name in ('scalarprod', 'base'): tsx.delete(name) - ts_base = genserie(datetime(2010, 1, 1), 'D', 3, [1]) + ts_base = genserie(datetime(2010, 1, 1), 'd', 3, [1]) tsx.update('base', ts_base, 'test') tsx.register_formula( @@ -398,7 +398,7 @@ # get_many, republications & revision date for idx, idate in enumerate(pd.date_range(datetime(2015, 1, 1), datetime(2015, 1, 3), - freq='D', + freq='d', tz='utc')): tsx.update('comp1', ts_base * idx, 'test', insertion_date=idate) @@ -459,7 +459,7 @@ for name in ('scalarprod', 'base', 'comp1', 'comp2', 'repusum', 'repuprio'): tsa2.delete(name) - ts_base = genserie(datetime(2010, 1, 1), 'D', 3, [1]) + ts_base = genserie(datetime(2010, 1, 1), 'd', 3, [1]) tsa2.update('base', ts_base, 'test') tsa2.register_formula( @@ -479,7 +479,7 @@ # get_many, republications & revision date for idx, idate in enumerate(pd.date_range(datetime(2015, 1, 1), datetime(2015, 1, 3), - freq='D', + freq='d', tz='utc')): tsa2.update('comp1', ts_base * idx, 'test', insertion_date=idate) @@ -534,9 +534,9 @@ def test_origin(tsx): - ts_real = genserie(datetime(2010, 1, 1), 'D', 10, [1]) - ts_nomination = genserie(datetime(2010, 1, 1), 'D', 12, [2]) - ts_forecast = genserie(datetime(2010, 1, 1), 'D', 20, [3]) + ts_real = genserie(datetime(2010, 1, 1), 'd', 10, [1]) + ts_nomination = genserie(datetime(2010, 1, 1), 'd', 12, [2]) + ts_forecast = genserie(datetime(2010, 1, 1), 'd', 20, [3]) tsx.update('realised', ts_real, 'test') tsx.update('nominated', ts_nomination, 'test') @@ -600,9 +600,9 @@ # same test as above # tsa1: local with remote source # tsa2: remote source - ts_real = genserie(datetime(2010, 1, 1), 'D', 10, [1]) - ts_nomination = genserie(datetime(2010, 1, 1), 'D', 12, [2]) - ts_forecast = genserie(datetime(2010, 1, 1), 'D', 20, [3]) + ts_real = genserie(datetime(2010, 1, 1), 'd', 10, [1]) + ts_nomination = genserie(datetime(2010, 1, 1), 'd', 12, [2]) + ts_forecast = genserie(datetime(2010, 1, 1), 'd', 20, [3]) for name in ('realised', 'nominated', 'forecasted', 'serie5', 'serie6', 'serie7'): tsa2.delete(name) @@ -682,7 +682,7 @@ def test_find_bypolicy(tsx): - ts = genserie(utcdt(2023, 1, 1), 'D', 10, [1]) + ts = genserie(utcdt(2023, 1, 1), 'd', 10, [1]) tsx.update( 'find.base', ts, @@ -789,7 +789,7 @@ for idx, idate in enumerate( pd.date_range( utcdt(2022, 1, 1), - freq='D', + freq='d', periods=5 ) ): @@ -797,7 +797,7 @@ [1, 2, 3], index=pd.date_range( utcdt(2022, 1, 1 + idx), - freq='D', + freq='d', periods=3 ) ) @@ -975,7 +975,7 @@ [7] * 5, index=pd.date_range( utcdt(2022, 1, 10), - freq='D', + freq='d', periods=5 ) ) @@ -1020,7 +1020,7 @@ def test_cacheable_formulas(tsa1, tsa2): ts = pd.Series( [1, 2, 3], - index=pd.date_range(utcdt(2022, 1, 1), freq='D', periods=3) + index=pd.date_range(utcdt(2022, 1, 1), freq='d', periods=3) ) tsa1.update('cacheable-base-local', ts, 'Babar') tsa2.update('cacheable-base-remote', ts, 'Celeste') @@ -1098,7 +1098,7 @@ [1, 2, 3], index=pd.date_range( utcdt(2022, 1, i), - freq='D', + freq='d', periods=3 ) ) @@ -1156,7 +1156,7 @@ [1, 2, 3], index=pd.date_range( utcdt(2022, 1, 1 + i), - freq='D', + freq='d', periods=3 ) ), diff --git a/test/test_cache.py b/test/test_cache.py --- a/test/test_cache.py +++ b/test/test_cache.py @@ -154,7 +154,7 @@ [1., 2., 3.], index=pd.date_range( pd.Timestamp('2022-1-1'), - freq='D', periods=3 + freq='d', periods=3 ) ) @@ -257,7 +257,7 @@ for idx, idate in enumerate( pd.date_range( utcdt(2022, 1, 1), - freq='D', + freq='d', periods=5 ) ): @@ -265,7 +265,7 @@ [1, 2, 3], index=pd.date_range( utcdt(2022, 1, 1 + idx), - freq='D', + freq='d', periods=3 ) ) @@ -589,7 +589,7 @@ for idx, idate in enumerate( pd.date_range( utcdt(2022, 1, 1), - freq='D', + freq='d', periods=5 ) ): @@ -597,7 +597,7 @@ [1.1, 2.1, 3.1], index=pd.date_range( utcdt(2022, 1, 1 + idx), - freq='D', + freq='d', periods=3 ) ) @@ -671,7 +671,7 @@ [1, 2, 3], index=pd.date_range( utcdt(2022, 1, 1), - freq='D', + freq='d', periods=3 ) ) @@ -722,7 +722,7 @@ [1, 2, 3], index=pd.date_range( utcdt(2022, 1, 1), - freq='D', + freq='d', periods=3 ) ) @@ -818,7 +818,7 @@ [1, 2, 3], index=pd.date_range( utcdt(2022, 1, 1), - freq='D', + freq='d', periods=3 ) ) @@ -894,7 +894,7 @@ def test_formula_order(engine, tsh): ts = pd.Series( [1, 2, 3], - index=pd.date_range(utcdt(2022, 1, 1), periods=3, freq='D') + index=pd.date_range(utcdt(2022, 1, 1), periods=3, freq='d') ) tsh.update( @@ -954,7 +954,7 @@ def test_formula_order_two_series(engine, tsh): ts = pd.Series( [1, 2, 3], - index=pd.date_range(utcdt(2022, 1, 1), periods=3, freq='D') + index=pd.date_range(utcdt(2022, 1, 1), periods=3, freq='d') ) tsh.update( engine, @@ -1008,7 +1008,7 @@ [i] * 3, index=pd.date_range( utcdt(2022, 1, 1 + i), - freq='D', + freq='d', periods=3 ) ) @@ -1073,7 +1073,7 @@ range(3), index=pd.date_range( pd.Timestamp('2022-1-1'), - freq='D', + freq='d', periods=3 ) ), @@ -1126,7 +1126,7 @@ range(5), index=pd.date_range( pd.Timestamp('2022-1-1'), - freq='D', + freq='d', periods=5 ) ), @@ -1153,7 +1153,7 @@ range(7), index=pd.date_range( pd.Timestamp('2022-1-1'), - freq='D', + freq='d', periods=7 ) ), @@ -1179,7 +1179,7 @@ for m in range(1, 5): ts = pd.Series( [m] * 5, - index=pd.date_range(f'2022-{m}-1', freq='D', periods=5) + index=pd.date_range(f'2022-{m}-1', freq='d', periods=5) ) tsa.update( 'deep-fried', @@ -1371,7 +1371,7 @@ [1.] * 3, index=pd.date_range( pd.Timestamp('2022-1-1'), - freq='D', periods=3 + freq='d', periods=3 ) ) tsa.update( @@ -1419,7 +1419,7 @@ [1.] * 5, index=pd.date_range( pd.Timestamp('2022-1-1'), - freq='D', periods=5 + freq='d', periods=5 ) ) tsa.update( @@ -1454,7 +1454,7 @@ [1.] * 3, index=pd.date_range( pd.Timestamp('2022-1-1'), - freq='D', periods=3 + freq='d', periods=3 ) ) tsa.update( @@ -1506,7 +1506,7 @@ [0] * 5, index=pd.date_range( pd.Timestamp('2022-1-1'), - freq='D', periods=5 + freq='d', periods=5 ) ) tsa.update( @@ -1549,14 +1549,14 @@ # smaller that the original series) tsh.cache.update( engine, - ts[:3] + 10 , + ts.iloc[:3] + 10 , 'formula-revdate', 'pseudo-cache', insertion_date=pd.Timestamp('2022-1-1 01:00:00', tz='UTC') ) tsh.cache.update( engine, - ts[:3] + 11 , + ts.iloc[:3] + 11 , 'formula-revdate', 'pseudo-cache', insertion_date=pd.Timestamp('2022-1-2 01:00:00', tz='UTC') @@ -1642,7 +1642,7 @@ [i], index=pd.date_range( pd.Timestamp(f'2022-1-{i}', tz='utc'), - freq='D', + freq='d', periods=1 ) ), @@ -1732,7 +1732,7 @@ [1., 2., 3.], index=pd.date_range( pd.Timestamp('2022-1-1'), - freq='D', periods=3 + freq='d', periods=3 ) ) @@ -1740,7 +1740,7 @@ [[0, 1, 2], [1, 2, 3], [2, 3, 4]], index=pd.date_range( pd.Timestamp('2022-1-1'), - freq='D', periods=3 + freq='d', periods=3 ), columns=['a', 'b', 'c'] ) @@ -1873,7 +1873,7 @@ [1] * 7, index=pd.date_range( start=datetime(2014, 12, 31), - freq='D', + freq='d', periods=7, ) ) @@ -1948,7 +1948,7 @@ [2] * 7, index=pd.date_range( start=datetime(2022, 1, 25), - freq='D', + freq='d', periods=7, ) ) diff --git a/test/test_tsio.py b/test/test_tsio.py --- a/test/test_tsio.py +++ b/test/test_tsio.py @@ -30,9 +30,9 @@ def test_rename(engine, tsh): - tsh.update(engine, genserie(datetime(2010, 1, 1), 'D', 3), + tsh.update(engine, genserie(datetime(2010, 1, 1), 'd', 3), 'rename-me', 'Babar') - tsh.update(engine, genserie(datetime(2010, 1, 1), 'D', 3), + tsh.update(engine, genserie(datetime(2010, 1, 1), 'd', 3), 'rename-me', 'Celeste', manual=True) tsh.rename(engine, 'rename-me', 'renamed') @@ -53,7 +53,7 @@ with engine.begin() as cn: tsh.delete(cn, 'formula-then-primary') - series = genserie(datetime(2020, 1, 1), 'D', 3) + series = genserie(datetime(2020, 1, 1), 'd', 3) tsh.update(engine, series, 'formula-then-primary', 'Babar') series = tsh.get(engine, 'formula-then-primary') @@ -66,7 +66,7 @@ def test_manual_overrides(engine, tsh): # start testing manual overrides - ts_begin = genserie(datetime(2010, 1, 1), 'D', 5, [2.]) + ts_begin = genserie(datetime(2010, 1, 1), 'd', 5, [2.]) ts_begin.loc['2010-01-04'] = -1 tsh.update(engine, ts_begin, 'ts_mixte', 'test') @@ -84,7 +84,7 @@ assert not marker.any() # refresh all the period + 1 extra data point - ts_more = genserie(datetime(2010, 1, 2), 'D', 5, [2]) + ts_more = genserie(datetime(2010, 1, 2), 'd', 5, [2]) ts_more.loc['2010-01-04'] = -1 tsh.update(engine, ts_more, 'ts_mixte', 'test') @@ -99,7 +99,7 @@ # just append an extra data point # with no intersection with the previous ts - ts_one_more = genserie(datetime(2010, 1, 7), 'D', 1, [2]) + ts_one_more = genserie(datetime(2010, 1, 7), 'd', 1, [2]) tsh.update(engine, ts_one_more, 'ts_mixte', 'test') assert_df(""" @@ -116,7 +116,7 @@ # edit the bogus upstream data: -1 -> 3 # also edit the next value - ts_manual = genserie(datetime(2010, 1, 4), 'D', 2, [3]) + ts_manual = genserie(datetime(2010, 1, 4), 'd', 2, [3]) tsh.update(engine, ts_manual, 'ts_mixte', 'test', manual=True) assert tsh.supervision_status(engine, 'ts_mixte') == 'supervised' @@ -173,7 +173,7 @@ """, ts) # another iterleaved editing session - ts_edit = genserie(datetime(2010, 1, 4), 'D', 1, [2]) + ts_edit = genserie(datetime(2010, 1, 4), 'd', 1, [2]) tsh.update(engine, ts_edit, 'ts_mixte', 'test', manual=True) assert 2 == tsh.get(engine, 'ts_mixte')['2010-01-04'] # still ts, marker = tsh.get_ts_marker(engine, 'ts_mixte') @@ -218,10 +218,10 @@ 2010-01-07 2.0 """, ts_auto) - ts_manual = genserie(datetime(2010, 1, 5), 'D', 2, [3]) + ts_manual = genserie(datetime(2010, 1, 5), 'd', 2, [3]) tsh.update(engine, ts_manual, 'ts_mixte', 'test', manual=True) - ts_manual = genserie(datetime(2010, 1, 9), 'D', 1, [3]) + ts_manual = genserie(datetime(2010, 1, 9), 'd', 1, [3]) tsh.update(engine, ts_manual, 'ts_mixte', 'test', manual=True) tsh.update(engine, ts_auto, 'ts_mixte', 'test') @@ -269,7 +269,7 @@ def test_first_manual(engine, tsh): - ts_begin = genserie(datetime(2010, 1, 1), 'D', 10) + ts_begin = genserie(datetime(2010, 1, 1), 'd', 10) tsh.update(engine, ts_begin, 'ts_only', 'test', manual=True) assert_df(""" @@ -324,10 +324,10 @@ def test_more_manual(engine, tsh): - ts = genserie(datetime(2015, 1, 1), 'D', 5) + ts = genserie(datetime(2015, 1, 1), 'd', 5) tsh.update(engine, ts, 'ts_exp1', 'test') - ts_man = genserie(datetime(2015, 1, 3), 'D', 3, -1) + ts_man = genserie(datetime(2015, 1, 3), 'd', 3, -1) ts_man.iloc[-1] = np.nan # erasing of the laste value for the date 5/1/2015 tsh.update(engine, ts_man, 'ts_exp1', 'test', manual=True) @@ -351,19 +351,19 @@ def test_revision_date(engine, tsh): - ts = genserie(datetime(2010, 1, 4), 'D', 4, [1], name='truc') + ts = genserie(datetime(2010, 1, 4), 'd', 4, [1], name='truc') tsh.update( engine, ts, 'ts_through_time', 'test', insertion_date=pd.Timestamp(datetime(2015, 1, 1, 15, 43, 23), tz='UTC') ) - ts = genserie(datetime(2010, 1, 4), 'D', 4, [2], name='truc') + ts = genserie(datetime(2010, 1, 4), 'd', 4, [2], name='truc') tsh.update( engine, ts, 'ts_through_time', 'test', insertion_date=pd.Timestamp(datetime(2015, 1, 2, 15, 43, 23), tz='UTC') ) - ts = genserie(datetime(2010, 1, 4), 'D', 4, [3], name='truc') + ts = genserie(datetime(2010, 1, 4), 'd', 4, [3], name='truc') tsh.update( engine, ts, 'ts_through_time', 'test', insertion_date=pd.Timestamp(datetime(2015, 1, 3, 15, 43, 23), tz='UTC') @@ -410,7 +410,7 @@ def test_before_first_insertion(engine, tsh): - tsh.update(engine, genserie(datetime(2010, 1, 1), 'D', 11), 'ts_shtroumpf', 'test') + tsh.update(engine, genserie(datetime(2010, 1, 1), 'd', 11), 'ts_shtroumpf', 'test') # test get_marker with an unknown series vs a serie displayed with # a revision date before the first insertion @@ -431,7 +431,7 @@ for name in ('scalarprod', 'base', 'comp1', 'comp2', 'repusum', 'repuprio'): tsh.delete(cn, name) - ts_base = genserie(datetime(2010, 1, 1), 'D', 3, [1]) + ts_base = genserie(datetime(2010, 1, 1), 'd', 3, [1]) tsh.update(engine, ts_base, 'base', 'test') tsh.register_formula( @@ -451,7 +451,7 @@ # get_many, republications & revision date for idx, idate in enumerate(pd.date_range(datetime(2015, 1, 1), datetime(2015, 1, 3), - freq='D', + freq='d', tz='utc')): tsh.update(engine, ts_base * idx, 'comp1', 'test', insertion_date=idate) @@ -498,9 +498,9 @@ def test_origin(engine, tsh): - ts_real = genserie(datetime(2010, 1, 1), 'D', 10, [1]) - ts_nomination = genserie(datetime(2010, 1, 1), 'D', 12, [2]) - ts_forecast = genserie(datetime(2010, 1, 1), 'D', 20, [3]) + ts_real = genserie(datetime(2010, 1, 1), 'd', 10, [1]) + ts_nomination = genserie(datetime(2010, 1, 1), 'd', 12, [2]) + ts_forecast = genserie(datetime(2010, 1, 1), 'd', 20, [3]) tsh.update(engine, ts_real, 'realised', 'test') tsh.update(engine, ts_nomination, 'nominated', 'test') @@ -562,7 +562,7 @@ def test_na_and_delete(engine, tsh): - ts_repushed = genserie(datetime(2010, 1, 1), 'D', 11) + ts_repushed = genserie(datetime(2010, 1, 1), 'd', 11) ts_repushed[0:3] = np.nan tsh.update(engine, ts_repushed, 'ts_repushed', 'test') diff = tsh.update(engine, ts_repushed, 'ts_repushed', 'test') @@ -570,7 +570,7 @@ def test_exotic_name(engine, tsh): - ts = genserie(datetime(2010, 1, 1), 'D', 11) + ts = genserie(datetime(2010, 1, 1), 'd', 11) tsh.update(engine, ts, 'ts-with_dash', 'test') tsh.get(engine, 'ts-with_dash') @@ -579,8 +579,8 @@ tictac = False for insertion_date in pd.date_range(start=datetime(2015, 1, 1), end=datetime(2015, 1, 2), - freq='H'): - ts = genserie(start=insertion_date, freq='H', repeat=6) + freq='h'): + ts = genserie(start=insertion_date, freq='h', repeat=6) tsh.update(engine, ts, 'republication', 'test', insertion_date=pd.Timestamp(insertion_date, tz='UTC'), manual=tictac) @@ -622,10 +622,10 @@ dr = pd.date_range( start=datetime(2015, 1, 1), end=datetime(2015, 1, 2), - freq='H' + freq='h' ) for insertion_date in dr: - ts1 = genserie(start=insertion_date, freq='H', repeat=6) + ts1 = genserie(start=insertion_date, freq='h', repeat=6) ts2 = ts1 + 1 tsh.update( engine, ts1, 'rep1', 'test', @@ -728,7 +728,7 @@ def test_formula_metadata(engine, tsh): ts = pd.Series( [1, 2, 3], - index=pd.date_range(utcdt(2020, 1, 1), freq='D', periods=3) + index=pd.date_range(utcdt(2020, 1, 1), freq='d', periods=3) ) tsh.update( diff --git a/tshistory_refinery/cache.py b/tshistory_refinery/cache.py --- a/tshistory_refinery/cache.py +++ b/tshistory_refinery/cache.py @@ -1,4 +1,3 @@ -from datetime import datetime from contextlib import contextmanager from functools import cmp_to_key import traceback @@ -39,7 +38,7 @@ ): """ Validate each of the four parameters of a given cache policy """ badinputs = [] - env = {'now': datetime.utcnow()} + env = {'now': pd.Timestamp.utcnow()} for name, val in ( ('initial_revdate', initial_revdate), ('look_before', look_before), @@ -507,7 +506,7 @@ print(f'no idate over {initial_revdate} -> {now}, no refresh') return # that's an odd series, let's bail out - final_revdate = final_revdate or pd.Timestamp(datetime.utcnow(), tz='UTC') + final_revdate = final_revdate or pd.Timestamp.utcnow() if initial_revdate >= final_revdate: print('empty interval, nothing to do') return