Skip to content

Conversation

@jl-wynen
Copy link
Member

@jl-wynen jl-wynen commented Oct 15, 2025

First step towards #3687

Unfortunately, this leads to a bunch of type errors because Mypy does not understand the relationship between .is_binned and .bins. But once we make bins raise, we can just revert the 'Suppress temporary type error' commit.

if da.bins is not None:
da.bins.coords.pop(name, None)
if da.is_binned:
da.bins.coords.pop(name, None) # type: ignore[union-attr]
Copy link
Member

Choose a reason for hiding this comment

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

How about changing the type hint of bins right now, even if it may still return None. Then you can avoid suppressing everything (and having to remove it again later)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could do. No downstream package actually passes type checks at the moment anyway.

Comment on lines 598 to 601
"""
Returns helper :py:class:`scipp.Bins` allowing bin-wise operations
to be performed or `None` if not binned data.
"""
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to add a deprecation note for the None return behavior in the docstring?

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 was thinking of releasing this change, then adding a deprecation warning in the release after. Should I still add something in the docstring now?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think you can add a deprecation warning anyway, right? So why not put it into the docstring now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why not? We can raise a warning when .bins is called on an unbinned object.

Copy link
Member

Choose a reason for hiding this comment

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

But won't that give tons of false positives from uses such as

if da.bins is None:
  # do a
else:
  # do b

?

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe the order of releases, refactoring, and deprecation we had in mind was mismatching, so it may just be down to confusion!

Copy link
Member Author

Choose a reason for hiding this comment

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

My idea was just to insert an extra step by raising a warning and later change that to an error. This would allow people to still use the old approach before it gets properly disabled. But it would trip up our tests and force us to migrate.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, makes sense!

def _bins(obj: _O) -> Bins[_O]:
"""Returns helper :class:`scipp.Bins` for bin-wise operations.
.. attention::
Copy link
Member

@SimonHeybrock SimonHeybrock Oct 16, 2025

Choose a reason for hiding this comment

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

Didn't Sphinx have a specific tag for deprecation?

@jl-wynen jl-wynen enabled auto-merge October 17, 2025 06:29
@jl-wynen jl-wynen merged commit aea93a1 into main Oct 17, 2025
4 checks passed
@jl-wynen jl-wynen deleted the is_binned branch October 17, 2025 06:38
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.

3 participants