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

Add a new StatisticsError exception class #2760

Merged
merged 3 commits into from
Feb 8, 2023
Merged

Add a new StatisticsError exception class #2760

merged 3 commits into from
Feb 8, 2023

Conversation

sgillies
Copy link
Member

@sgillies sgillies commented Feb 8, 2023

Also make an outer with Env(): optional when using an opened dataset as a context manager.

Resolves #2759

Also make an outer `with Env():` optional when using an opened
dataset as a context manager.

Resolves #2759
@@ -439,6 +440,7 @@ cdef class DatasetBase:
self._closed = True

def __enter__(self):
self._env.enter_context(env_ctx_if_needed())
Copy link
Member Author

Choose a reason for hiding this comment

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

I feel dumb for not seeing this until now. I could have done this for 1.3.0!

Copy link
Member Author

@sgillies sgillies Feb 8, 2023

Choose a reason for hiding this comment

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

dataset.enter_context(Env()) is like a retroactive version of

with Env():
    with dataset as dataset:
        ...

It lets us add an outer context (Env()) to the inner one (dataset), from within the inner one.

@sgillies sgillies self-assigned this Feb 8, 2023
@sgillies sgillies added the bug label Feb 8, 2023
@sgillies sgillies added this to the 1.3.6 milestone Feb 8, 2023
@@ -60,13 +60,13 @@ def xy(
col : int
Pixel column.
z : float, optional
Height associated with coordinates. Primarily used for RPC based
coordinate transformations. Ignored for affine based
Copy link
Member Author

Choose a reason for hiding this comment

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

I looked in this module to remind myself how I was using ExitStack and found some trailing whitespace to remove. It's related 😉

@@ -72,16 +68,6 @@ def test_dataset_readonly_attributes(path_rgb_byte_tif):
dataset.crs = "foo"


def test_statistics(path_rgb_byte_tif):
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved to its own test module.

_ = dataset.statistics(1)

captured = capsys.readouterr()
assert "ERROR 1" not in captured.err
Copy link
Member Author

Choose a reason for hiding this comment

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

Without the change to _base.pyx, this assertion fails.

rasterio/_io.pyx Outdated Show resolved Hide resolved
Copy link
Member

@snowman2 snowman2 left a comment

Choose a reason for hiding this comment

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

Thanks @sgillies 👍

@sgillies sgillies merged commit 74d1302 into maint-1.3 Feb 8, 2023
@sgillies sgillies deleted the issue2759 branch February 8, 2023 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants