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

Use exceptions rather than assert statements for generator #63

Merged
merged 1 commit into from
May 18, 2022

Conversation

maxrjones
Copy link
Member

This PR changes two assert statements to exceptions for more informative feedback to the user, to prevent unexpected behavior if asserts are disabled in the interpreter, and to avoid returning a generator of length 0 if input_dim[dim] > ds.dims[dim] but (input_dim[dim] - input_overlap[dim]) > ds.dims[dim] (example below, assuming this is unwanted behavior).

import xbatcher
import xarray as xr
import numpy as np

size = 30
t = np.arange(size)
data = np.random.randn(size, size)
ds = xr.Dataset(
    {"A": xr.DataArray(data, coords={"time": t}, dims=("time", "x"))}
)
bgen_1 = ds.batch.generator(input_dims={'time': 40}, input_overlap={'time': 15})
len(bgen_1)

@codecov
Copy link

codecov bot commented May 18, 2022

Codecov Report

Merging #63 (34c4c1a) into main (34ca3f9) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main       #63   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines          134       136    +2     
  Branches        30        32    +2     
=========================================
+ Hits           134       136    +2     
Impacted Files Coverage Δ
xbatcher/generators.py 100.00% <100.00%> (ø)

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 34ca3f9...34c4c1a. Read the comment docs.

@jhamman
Copy link
Contributor

jhamman commented May 18, 2022

Thanks @meghanrjones!

@jhamman jhamman merged commit 05b978c into xarray-contrib:main May 18, 2022
@maxrjones maxrjones deleted the slice-exceptions branch May 19, 2022 01:27
@maxrjones maxrjones added the maintenance Maintenance tasks label Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants