FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

datetime plotting broken on master · Issue #17867 · matplotlib/matplotlib · GitHub

Repository navigation

datetime plotting broken on master #17867

Closed

Description

Bug report

On master branch, plotting datetimes appears to be broken. This error bisects to a793bde in #17022

Code for reproduction

import matplotlib.pyplot as plt
from datetime import datetime

fig, ax = plt.subplots()
ax.plot(datetime.now(), 1)
plt.show()

Actual outcome

  File "test.py", line 5, in <module>
    ax.plot(datetime.now(), 1)
  File "/Users/dstansby/github/matplotlib/lib/matplotlib/axes/_axes.py", line 1745, in plot
    self.add_line(line)
  File "/Users/dstansby/github/matplotlib/lib/matplotlib/axes/_base.py", line 1977, in add_line
    self._update_line_limits(line)
  File "/Users/dstansby/github/matplotlib/lib/matplotlib/axes/_base.py", line 1999, in _update_line_limits
    path = line.get_path()
  File "/Users/dstansby/github/matplotlib/lib/matplotlib/lines.py", line 1011, in get_path
    self.recache()
  File "/Users/dstansby/github/matplotlib/lib/matplotlib/lines.py", line 653, in recache
    x = _to_unmasked_float_array(xconv).ravel()
  File "/Users/dstansby/github/matplotlib/lib/matplotlib/cbook/__init__.py", line 1298, in _to_unmasked_float_array
    return np.asarray(x, float)
  File "/Users/dstansby/miniconda3/envs/dev/lib/python3.8/site-packages/numpy/core/_asarray.py", line 83, in asarray
    return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number, not 'datetime.datetime'

Expected outcome

Matplotlib version

  • Operating system:
  • Matplotlib version:
  • Matplotlib backend (print(matplotlib.get_backend())):
  • Python version:
  • Jupyter version (if applicable):
  • Other libraries:

Activity

  1. dstansby commented on Jul 9, 2020

    MemberAuthor

    The issue seems to be that datetime converters are no longer being registered. If I print maptlotlib.untis.registry before plotting, it does not contain any datetime converters.

  2. dstansby commented on Jul 9, 2020

    MemberAuthor

    My maptlotlibrc is

    backend : qt5agg
    figure.figsize : 10, 8
    

    So I think the issue is no date.converter entry means that the converters are never being registered. As an aside, does the test suite run the tests with an empty matplotlibrc at all? I'm guessing this error was never caught because the tests are always run with a fully populated matplotlibrc.

  3. jklymak commented on Jul 9, 2020

    Member

    So at first I could not reproduce this error.

    git checkout -v 3.2.1
    pip install -e .
    git checkout placeholder
    python testDates.py
    

    I get many rcParam errors and deprecations. If I do

    git checkout placeholder
    pip install -e .
    python testDates.py
    

    then I can reproduce.

    To me, the underlying issue is that the matplotlibrc has to be setup properly via a pip install whereas before it just was. I believe that the change that made this an issue is #15029. From a developer point of view, its a substantial regression to have to pip install for rcParam changes. ping @anntzer about that.

    I'll try and figure out how to get the rcParam set up properly here. Obviously I did something wrong in #17022.

  4. anntzer commented on Jul 9, 2020

    Contributor

    It doesn't seem too hard to add some logic when constructing rcParamsDefault so that if it detects it's in an editable install, then it doesn't use matplotlib/mpl-data/matplotlibrc but rather matplotlibrc.template (still with the special, comment-removing loader).

    (PS: I need to take a bit of time off devel because of work, so I won't implement the fix right now. As usual, if that turns out to be too bad of a blocker, feel free to revert #15029 and I'll redo it in a better way in the future.)

  5. jklymak commented on Jul 9, 2020

    Member

    OK, but I'm confused about the pathway here. I thought the defaults were all validated when the rcParams are set up. Is that not the case?

  6. dstansby commented on Jul 9, 2020

    MemberAuthor

    A bit of debug, the rcParam validation is being hit (so I don't think this is #15029's fault), but sys.modules.get("matplotlib.dates") is returning None for me in the following block, which means no converter is registered.

    def _validate_date_converter(s):
        s = validate_string(s)
        mdates = sys.modules.get("matplotlib.dates")
        if mdates:
            mdates._rcParam_helper.set_converter(s)
  7. jklymak commented on Jul 9, 2020

    Member

    OK, well see the fix. Still not 100% sure this fixes all the ways the rcParams can be set up.

  8. added this to the v3.4.0 milestone on Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL