Skip to content

Comments

Helper function for dropping timeslice#392

Merged
tsmbland merged 8 commits intodevelopfrom
drop_timeslice
Jul 4, 2024
Merged

Helper function for dropping timeslice#392
tsmbland merged 8 commits intodevelopfrom
drop_timeslice

Conversation

@tsmbland
Copy link
Collaborator

@tsmbland tsmbland commented Jul 2, 2024

Description

Adds a helper function for dropping the timeslice variable from data arrays, and uses this throughout the code instead of drop_vars(["timeslice", "month", "day", "hour"])

This partially fixes #363, but a few other changes will be required which I'm addressing in #381

Type of change

Please add a line in the relevant section of
CHANGELOG.md to
document the change (include PR #) - note reverse order of PR #s.

  • New feature (non-breaking change which adds functionality)
  • Optimization (non-breaking, back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (whatever its nature)

Key checklist

  • All tests pass: $ python -m pytest
  • The documentation builds and looks OK: $ python -m sphinx -b html docs docs/build

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@codecov
Copy link

codecov bot commented Jul 2, 2024

Codecov Report

Attention: Patch coverage is 91.66667% with 3 lines in your changes missing coverage. Please review.

Project coverage is 71.37%. Comparing base (36f8c77) to head (6e5cfd9).

Files Patch % Lines
src/muse/sectors/preset_sector.py 60.00% 2 Missing ⚠️
src/muse/objectives.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #392      +/-   ##
===========================================
+ Coverage    71.34%   71.37%   +0.02%     
===========================================
  Files           44       44              
  Lines         5916     5928      +12     
  Branches      1168     1169       +1     
===========================================
+ Hits          4221     4231      +10     
- Misses        1373     1374       +1     
- Partials       322      323       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tsmbland tsmbland marked this pull request as ready for review July 2, 2024 14:06
@tsmbland tsmbland requested review from alexdewar and dalonsoa July 2, 2024 14:07
@tsmbland tsmbland self-assigned this Jul 2, 2024
Copy link
Collaborator

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

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

Given that you're on it, add a dedicated tests that checks the new function.

return convert_timeslice(DataArray([nhours]), timeslices).squeeze()


def drop_timeslice(data: DataArray):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ideally, add output type:

Suggested change
def drop_timeslice(data: DataArray):
def drop_timeslice(data: DataArray) -> DataArray:

Copy link
Collaborator

@alexdewar alexdewar left a comment

Choose a reason for hiding this comment

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

I've made a small suggestion (that probs won't work) but other than that, LGTM.

if "timeslice" not in data.dims:
return data

return data.drop_vars([c for c in data.timeslice.indexes])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would this work:

Suggested change
return data.drop_vars([c for c in data.timeslice.indexes])
return data.drop_vars(data.timeslice.indexes)

If not, how about:

Suggested change
return data.drop_vars([c for c in data.timeslice.indexes])
return data.drop_vars(list(data.timeslice.indexes))

@tsmbland
Copy link
Collaborator Author

tsmbland commented Jul 4, 2024

@dalonsoa Would you mind taking a quick look at this so I can merge it?

Copy link
Collaborator

@dalonsoa dalonsoa left a comment

Choose a reason for hiding this comment

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

LGTM! Sorry, I didn't realized the changes had been implemented.

@tsmbland tsmbland enabled auto-merge July 4, 2024 08:17
@tsmbland tsmbland merged commit 0d54942 into develop Jul 4, 2024
@tsmbland tsmbland deleted the drop_timeslice branch July 4, 2024 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Timeslice level names are no longer configurable [BUG]

3 participants