Skip to content

Create BaseReconciler #1054

Merged
merged 10 commits into from
Dec 28, 2022
Merged

Create BaseReconciler #1054

merged 10 commits into from
Dec 28, 2022

Conversation

alex-hse-repository
Copy link
Collaborator

Before submitting (must do checklist)

  • Did you read the contribution guide?
  • Did you update the docs? We use Numpy format for all the methods and classes.
  • Did you write any new necessary tests?
  • Did you update the CHANGELOG?

Proposed Changes

Closing issues

closes #1032

@codecov-commenter
Copy link

codecov-commenter commented Dec 27, 2022

Codecov Report

❗ No coverage uploaded for pull request base (hierarchical_pipeline@0d05503). Click here to learn what that means.
The diff coverage is n/a.

@@                   Coverage Diff                    @@
##             hierarchical_pipeline    #1054   +/-   ##
========================================================
  Coverage                         ?   86.37%           
========================================================
  Files                            ?      166           
  Lines                            ?     8839           
  Branches                         ?        0           
========================================================
  Hits                             ?     7635           
  Misses                           ?     1204           
  Partials                         ?        0           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@github-actions
Copy link

github-actions bot commented Dec 27, 2022

@github-actions github-actions bot temporarily deployed to pull request December 27, 2022 06:33 Inactive
etna/reconciliation/base.py Outdated Show resolved Hide resolved
if ts.current_df_level != self.source_level:
raise ValueError(f"Dataset should be on the {self.source_level} level!")

current_level_segments = ts.hierarchical_structure.get_level_segments(level_name=self.source_level)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this lines before check? In such case, we will check that target and source levels are parts of the hierarchy and, after that, we will check that dataset at the valid level.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call of this methods requires some movements inside)
I think it is better to check the more explicit requirements to the input data(has hierarchy/current level = source level...)
Also the code structure is better now as all the checks are at the beginning and are separate from the other logic

ts_aggregated = ts.get_level_dataset(target_level=self.source_level)
return ts_aggregated

def reconcile(self, ts: TSDataset) -> TSDataset:
Copy link
Collaborator

@brsnw250 brsnw250 Dec 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here we also need to check if the target level is higher than the source.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not required here as this method is common for both top-down and bottom-up

target_level_segments = ts.hierarchical_structure.get_level_segments(level_name=self.target_level)

current_level_values = ts[:, current_level_segments, "target"].values
target_level_values = current_level_values @ self.mapping_matrix.T
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it work properly with series that starts at different timestamps?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should, we do the same thing here and have tests with nans

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is why I thought of moving this logic to get_level_dataset as it is almost the same

def test_aggregate_fails_low_source_level(hierarchical_ts):
ts_market_level = hierarchical_ts.get_level_dataset(target_level="market")
reconciliator = DummyReconciliator(target_level="level", source_level="product")
with pytest.raises(ValueError, match=""):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we check error message more specifically?

Copy link
Collaborator Author

@alex-hse-repository alex-hse-repository Dec 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My fail)


def test_reconcile_not_fitted_fails(hierarchical_ts):
reconciliator = DummyReconciliator(target_level="level", source_level="product")
with pytest.raises(ValueError, match=f"Reconciliator is not fitted!"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need f-string here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't)

Copy link
Contributor

@Mr-Geekman Mr-Geekman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little issues, look at comments above.

@github-actions github-actions bot temporarily deployed to pull request December 28, 2022 05:00 Inactive
@alex-hse-repository alex-hse-repository merged commit 363b013 into hierarchical_pipeline Dec 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants