Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement map method for TimeSeries #163

Merged
merged 7 commits into from
Jul 23, 2020
Merged

Implement map method for TimeSeries #163

merged 7 commits into from
Jul 23, 2020

Conversation

Lovkush-A
Copy link
Contributor

Fixes #121

Summary

An implementation for map is added. It uses pandas' applymap method.
A jupyter notebook is included to show the tests conducted.

Other Information

I have added a couple of TODOs:

  • check if typing is correct
  • check if we need to add any error checking/raises of potential errors

An implementation for map is added. It uses pandas' applymap method.
A jupyter notebook to show the tests conducted.

Resolves: #121
@pennfranc
Copy link
Contributor

@Lovkush-A Thanks for your PR! I like your approach but have a couple of comments:

  1. As you pointed out in the comment, some checks might be needed here. Since we're directly accessing pandas DataFrame columns, it might be good to check whether the given columns are within range first. To do this, you could use our raise_if_not function from the logging module.
  2. I like your tests. But I think it would be better to implement them as unit tests rather than a notebook.

Unit tests test_map.py added.
Included a small check, that the indices are in a valid range, in map method in TimeSeries class.
@Lovkush-A
Copy link
Contributor Author

@pennfranc

  1. Done.
  2. Done. (At least I think it is done. I do not know how to test the tests...!)

@hrzn hrzn requested a review from grll July 22, 2020 20:16
darts/timeseries.py Outdated Show resolved Hide resolved
darts/timeseries.py Outdated Show resolved Hide resolved

def map(self,
fn: Callable[[float], float],
cols: Optional[Union[List[int], int]] = None) -> 'TimeSeries':
Copy link
Contributor

Choose a reason for hiding this comment

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

@grll you'll probably have to change this as part of you refactoring

Copy link
Contributor

Choose a reason for hiding this comment

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

yes we would need to replace int indexing with str indexing but nothing too serious here

darts/timeseries.py Outdated Show resolved Hide resolved
darts/timeseries.py Outdated Show resolved Hide resolved
darts/tests/test_map.py Outdated Show resolved Hide resolved
darts/tests/test_map.py Outdated Show resolved Hide resolved
darts/tests/test_map.py Outdated Show resolved Hide resolved
darts/tests/test_map.py Outdated Show resolved Hide resolved
darts/tests/test_map.py Outdated Show resolved Hide resolved
Following hrzn's advice, various minor adjustments were made:
* Correct various spacing/wording inconsistencies
* Move contents of test_map.py into test_timeseries.py
* Added sanity test case to tests for map
* Changed type hints to np.number
* Removed an unncessary call to self.pd_dataframe()
darts/timeseries.py Outdated Show resolved Hide resolved
@pennfranc pennfranc self-requested a review July 23, 2020 13:41
Copy link
Contributor

@pennfranc pennfranc left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@TheMP TheMP merged commit 117713f into unit8co:develop Jul 23, 2020
@Lovkush-A Lovkush-A deleted the map-method branch July 23, 2020 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants