diff --git a/outatime/timeseries/expr.py b/outatime/timeseries/expr.py index 8fc38f1..05dfabe 100644 --- a/outatime/timeseries/expr.py +++ b/outatime/timeseries/expr.py @@ -3,9 +3,9 @@ def take_first_available(a, b): - if all([a, b]): + if a is not None: return a - elif b: + elif b is not None: return b else: raise Exception("Both arguments are None.") @@ -19,20 +19,23 @@ def intersection(tsl_a: TimeSeries, tsl_b: TimeSeries, conflict_method=take_firs Args: tsl_a (TimeSeries): First input time series. tsl_b (TimeSeries): Second input time series. + conflict_method (None, optional): Method to apply when choosing + data for matching days. Defaults to take_first_available. Returns: TimeSeries: Output timeseries with shared days. """ - intersection_dates = tsl_a.dates and tsl_b.dates - res = [] + intersection_dates = list(set(tsl_a.dates) & set(tsl_b.dates)) + intersection_dates.sort() + intersection_result = [] for int_date in intersection_dates: - res.append( + intersection_result.append( TimeSeriesData( day=int_date, data=conflict_method(tsl_a.get(day=int_date).data, tsl_b.get(day=int_date).data) ) ) - return TimeSeries(res) + return TimeSeries(intersection_result) def union(tsl_a: TimeSeries, tsl_b: TimeSeries, conflict_method=take_first_available) -> TimeSeries: @@ -43,17 +46,20 @@ def union(tsl_a: TimeSeries, tsl_b: TimeSeries, conflict_method=take_first_avail Args: tsl_a (TimeSeries): First input time series. tsl_b (TimeSeries): Second input time series. + conflict_method (None, optional): Method to apply when choosing + data for matching days. Defaults to take_first_available. Returns: TimeSeries: Output timeseries with all days. """ - union_dates = tsl_a.dates or tsl_b.dates - res = [] - for int_date in union_dates: - res.append( + union_dates = list(set(tsl_a.dates) | set(tsl_b.dates)) + union_dates.sort() + union_result = [] + for uni_date in union_dates: + union_result.append( TimeSeriesData( - day=int_date, - data=conflict_method(tsl_a.get(day=int_date).data, tsl_b.get(day=int_date).data) + day=uni_date, + data=conflict_method(tsl_a.get(day=uni_date).data, tsl_b.get(day=uni_date).data) ) ) - return TimeSeries(res) + return TimeSeries(union_result) diff --git a/setup.py b/setup.py index e03b722..814c06d 100644 --- a/setup.py +++ b/setup.py @@ -3,12 +3,12 @@ with open("README.md", "r", encoding="utf-8") as fh: long_description = fh.read() long_description = long_description.split("

")[1] - long_description = "![](https://github.com/SynStratos/outatime/blob/main/docs/outatime_banner.png)" + long_description + long_description = "# OUTATIME" + long_description setuptools.setup( name='outatime', packages=setuptools.find_packages(), - version='1.0.2', + version='1.0.3', description='Python framework to manage time series.', long_description=long_description, long_description_content_type="text/markdown",