matplotlib icon indicating copy to clipboard operation
matplotlib copied to clipboard

BUG:datetime list starting with none

Open MikiPWata opened this issue 3 years ago • 6 comments

PR Summary

#23580

  • cbook/init.py
    • modified safe_first_element() to obtain the first non-None element
  • test_cbook.py
    • added a test for safe_first_element()

PR Checklist

Tests and Styling

  • [x] Has pytest style unit tests (and pytest passes).
  • [x] Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [ N/A] New features are documented, with examples if plot related.
  • [ N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [ N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [ N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).

MikiPWata avatar Aug 08 '22 22:08 MikiPWata

@MikiPWata Do you feel comfortable squashing this to one commit?

tacaswell avatar Aug 09 '22 02:08 tacaswell

@MikiPWata Do you feel comfortable squashing this to one commit?

yes! I will squash them into 1 commit

MikiPWata avatar Aug 09 '22 02:08 MikiPWata

Thank you, this is now waiting for a second reviewer to merge.

tacaswell avatar Aug 09 '22 02:08 tacaswell

Please squash to one commit again.

Doing this as

    return next(val for val in obj if not (skip_none and val is None))   # I _think_ this logic is correct

might be a bit more elegant.

tacaswell avatar Aug 09 '22 19:08 tacaswell

not sure why many pytests are failing....

MikiPWata avatar Aug 10 '22 02:08 MikiPWata

Test failures are likely unrelated https://gitter.im/matplotlib/matplotlib?at=62f2d60b9d3c186299235d4e

timhoffm avatar Aug 10 '22 10:08 timhoffm

And with the suggested changes we need to find all our usage of safe_first_element and replace with _safe_first_non_none.

This way we (internally) always use the new behavior, if anyone is using this method for their own reasons they keep the same old behavior, and we only have one copy of the logic!

tacaswell avatar Aug 11 '22 03:08 tacaswell

I think these test failures are real and caused by the changes in this PR.

tacaswell avatar Aug 11 '22 03:08 tacaswell

And with the suggested changes we need to find all our usage of safe_first_element and replace with _safe_first_non_none.

This way we (internally) always use the new behavior, if anyone is using this method for their own reasons they keep the same old behavior, and we only have one copy of the logic!

I have also changed all safe_first_element() in test files to _safe_first_none().

MikiPWata avatar Aug 11 '22 19:08 MikiPWata

Thanks @MikiPWata!

jklymak avatar Aug 11 '22 21:08 jklymak