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

linslope #307

Merged
merged 10 commits into from
May 8, 2021
Merged

linslope #307

merged 10 commits into from
May 8, 2021

Conversation

raybellwaves
Copy link
Member

@raybellwaves raybellwaves commented May 7, 2021

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Closes #284 (linslope)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance (if you touched existing code run asv to detect performance changes)
  • refactoring

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. This could point to a cell in the updated notebooks. Or a snippet of code with accompanying figures here.

Checklist (while developing)

  • I have added docstrings to all new functions.
  • I have commented my code, particularly in hard-to-understand areas
  • Tests added for pytest, if necessary.

Pre-Merge Checklist (final steps)

  • I have rebased onto main or develop (wherever I am merging) and dealt with any conflicts.
  • I have squashed commits to a reasonable amount, and force-pushed the squashed commits.

References

Please add any references to manuscripts, textbooks, etc.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@pep8speaks
Copy link

pep8speaks commented May 7, 2021

Hello @raybellwaves! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-05-08 23:44:06 UTC

@raybellwaves raybellwaves mentioned this pull request May 7, 2021
Copy link
Collaborator

@aaronspring aaronspring left a comment

Choose a reason for hiding this comment

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

implementation looks good to me

@raybellwaves
Copy link
Member Author

Thanks i'll checkout polyfit. Could you give me a drop in of it for the following:

import xarray as xr
import pandas as pd
import numpy as np
import xskillscore as xs
from scipy.stats import linregress

stores = np.arange(100)
skus = np.arange(100)
dates = pd.date_range("1/1/2020", "1/10/2020", freq="D")

rows = []
for _, date in enumerate(dates):
    for _, store in enumerate(stores):
        for _, sku in enumerate(skus):
            rows.append(
                dict(
                    {
                        "DATE": date,
                        "STORE": store,
                        "SKU": sku,
                        "QUANTITY_SOLD": np.random.randint(9) + 1,
                    }
                )
            )
df = pd.DataFrame(rows)
df.rename(columns={"QUANTITY_SOLD": "y"}, inplace=True)
df.set_index(['DATE', 'STORE', 'SKU'], inplace=True)
noise = np.random.uniform(-1, 1, size=len(df['y']))
df['yhat'] = (df['y'] + (df['y'] * noise)).astype(int)

df.groupby(['STORE', 'SKU']).apply(lambda x: linregress(x.y, x.yhat)[0])

ds = df.to_xarray()
ds.xs.linslope('y', 'yhat', 'DATE')

Am aware of @bradyrx's implementation of this which grabs all output. Similar to pearson_r and pearson_r_p_value I tend favor separate functions.

My motivation here is the example above (taken from raybellwaves/xskillscore-tutorial#3). I have a pandas.DataFrame and I want to do some metrics on it including slope.

@aaronspring
Copy link
Collaborator

What do you mean by drop in on it? Feedback?

@raybellwaves
Copy link
Member Author

raybellwaves commented May 7, 2021 via email

@raybellwaves

This comment has been minimized.

@aaronspring

This comment has been minimized.

@aaronspring
Copy link
Collaborator

How to use polyfit as a replacement for linregress (linslope) on xarray
objects. I see there isn’t an example in the docstring

On Fri, May 7, 2021 at 6:31 PM Aaron Spring @.***>
wrote:

What do you mean by drop in on it? Feedback?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#307 (comment),
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AEC6DZGLOLJ3ZGSZOHZS5ATTMRS4RANCNFSM44LBZ7AA
.

pydata/xarray#5278

But I think less functionality than linregress, so go on with this PR

@raybellwaves
Copy link
Member Author

failures addressed in #309

@raybellwaves raybellwaves mentioned this pull request May 8, 2021
10 tasks
@raybellwaves raybellwaves reopened this May 8, 2021
@codecov
Copy link

codecov bot commented May 8, 2021

Codecov Report

Merging #307 (6a76bdc) into main (54ff8f2) will increase coverage by 0.07%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #307      +/-   ##
==========================================
+ Coverage   94.50%   94.57%   +0.07%     
==========================================
  Files          23       23              
  Lines        2566     2601      +35     
==========================================
+ Hits         2425     2460      +35     
  Misses        141      141              
Impacted Files Coverage Δ
xskillscore/__init__.py 84.61% <ø> (ø)
xskillscore/tests/test_accessor_deterministic.py 100.00% <ø> (ø)
xskillscore/tests/test_deterministic.py 100.00% <ø> (ø)
xskillscore/tests/test_gridded_metrics.py 100.00% <ø> (ø)
xskillscore/tests/test_mask_skipna.py 100.00% <ø> (ø)
xskillscore/tests/test_skipna_functionality.py 100.00% <ø> (ø)
xskillscore/core/accessor.py 100.00% <100.00%> (ø)
xskillscore/core/deterministic.py 97.69% <100.00%> (+0.15%) ⬆️
xskillscore/core/np_deterministic.py 99.23% <100.00%> (+0.05%) ⬆️
xskillscore/tests/test_metric_results_accurate.py 100.00% <100.00%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e4c49d...6a76bdc. Read the comment docs.

@raybellwaves
Copy link
Member Author

@aaronspring anything else before I merge? Planning on a release after this.

@aaronspring
Copy link
Collaborator

I am fine

Co-authored-by: Aaron Spring <aaronspring@users.noreply.github.com>
@raybellwaves raybellwaves merged commit a2176b5 into xarray-contrib:main May 8, 2021
@raybellwaves raybellwaves deleted the add-linslope branch May 8, 2021 23:48
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.

metrics to add
3 participants