Skip to content

Conversation

@connoraird
Copy link
Contributor

@connoraird connoraird commented Nov 12, 2025

Description

Removed requirement for xp to be passed into redshift_grid and fixed_zbins. Now the default library used will be numpy.

Fixes: #770

Changelog entry

Fixed: redshift_grid and fixed_zbins no longer rely on xp being passed. Now defaults to numpy.

Checks

  • Is your code passing linting?
  • Is your code passing tests?
  • Have you added additional tests (if required)?
  • Have you modified/extended the documentation (if required)?
  • Have you added a one-liner changelog entry above (if required)?

@connoraird connoraird self-assigned this Nov 12, 2025
@connoraird connoraird added the bug Something isn't working label Nov 12, 2025
@connoraird connoraird changed the title Default to numpy for redshift_grid if no xp is provided gh-770: Default to numpy for redshift_grid if no xp is provided Nov 12, 2025
@connoraird connoraird requested a review from ntessore November 12, 2025 15:16
@connoraird connoraird changed the title gh-770: Default to numpy for redshift_grid if no xp is provided gh-770: Default to numpy for redshift_grid and fixed_zbins if no xp is provided Nov 12, 2025
@ntessore
Copy link
Collaborator

Thanks for looking into this! How about we create a default_xp() function that could evolve over time? (I am inspired by np.random.default_rng() here.)

@connoraird
Copy link
Contributor Author

Thanks for looking into this! How about we create a default_xp() function that could evolve over time? (I am inspired by np.random.default_rng() here.)

Sounds like a great idea

def default_xp() -> ModuleType:
"""Returns the library backend we default to if none is specified by the user."""
warnings.warn(
f"No array library has been provided for call to {inspect.stack()[1].function}",
Copy link
Member

Choose a reason for hiding this comment

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

Will this work every time?

Copy link
Contributor Author

@connoraird connoraird Nov 13, 2025

Choose a reason for hiding this comment

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

¯\_(ツ)_/¯

Would you rather leave out the calling function name?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe? When we call import_numpy elsewhere, the CompatibleBackendNotFoundError doesn't say where the backend is missing

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's fine for users to use GLASS as a CPU code so I wouldn't warn on default_xp(), at least for the time being.

# check num input

num = 5
with pytest.warns(
Copy link
Member

Choose a reason for hiding this comment

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

These aren't relevant any more, see test failures

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

redshift_grid() requires backend

4 participants