Skip to content

Support kwargs only calls to contour #24747

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

Closed
wants to merge 1 commit into from

Conversation

oscargus
Copy link
Member

PR Summary

Closes #24743

Check that there is at least one element in args before accessing it.

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@oscargus oscargus added Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. API: argument checking topic: contour labels Dec 16, 2022
@oscargus oscargus added this to the v3.7.0 milestone Dec 16, 2022
@chahak13
Copy link
Contributor

@oscargus this will fail because of _contour_args in this line

x, y, z = self._contour_args(args, kwargs)

It'll need a check in that function too the if statements don't check non-zero len(args)
(Sorry, I was just about to raise a PR for this too)

@chahak13
Copy link
Contributor

Something like this should work (this will error out on no positional args, will need changes)

-       if nargs <= 2:
-           z = ma.asarray(args[0], dtype=np.float64)
-           x, y = self._initialize_x_y(z)
-           args = args[1:]
-       elif nargs <= 4:
-           x, y, z = self._check_xyz(args[:3], kwargs)
-           args = args[3:]
-       else:
-           raise _api.nargs_error(fn, takes="from 1 to 4", given=nargs)
+       if 0 < nargs <= 2:
+           z = ma.asarray(args[0], dtype=np.float64)
+           x, y = self._initialize_x_y(z)
+           args = args[1:]
+       elif 2 < nargs <= 4:
+           x, y, z = self._check_xyz(args[:3], kwargs)
+           args = args[3:]
+       else:
+           raise _api.nargs_error(fn, takes="from 1 to 4", given=nargs)

Though, I do have a question about allowing passing Z as a keyword argument or let it be a positional argument and error out if none are given? This is what the quiver PR also did.

@oscargus
Copy link
Member Author

oscargus commented Dec 16, 2022

Yeah, I noticed that as well (although it did work when running it interactively strangely enough). I was about to start extracting X, Y, and Z from the kwargs at some stage, but as this wasn't as quick as I thought I'll move this to draft for now. Feel free to prepare a better PR.

I think your fix, checking that there is at least one argument, is good to have anyway, but in the long run I think that X, Y, and Z should be extracted if kwargs (before that check).

@oscargus oscargus marked this pull request as draft December 16, 2022 13:48
@oscargus oscargus removed the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Dec 16, 2022
@oscargus oscargus closed this Dec 16, 2022
@oscargus oscargus deleted the contourkwargs branch December 16, 2022 16:23
@tacaswell tacaswell removed this from the v3.7.0 milestone Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: contour raises IndexError if Z is specified as keyword argument
3 participants