Ticket #94 (new defect)

Opened 10 months ago

Last modified 10 months ago

TypeError in plotlib - with fix

Reported by: timcera Owned by: pierregm
Priority: major Milestone:
Component: timeseries Version:
Keywords: plotlib TypeError fmt Cc:

Description

At the bottom is a fix for the following traceback...

Traceback (most recent call last):
  File "C:\Python25\lib\site-packages\matplotlib\backends\backend_qt4.py", line 128, in mouseMoveEvent
    FigureCanvasBase.motion_notify_event( self, x, y )
  File "C:\Python25\lib\site-packages\matplotlib\backend_bases.py", line 1245, in motion_notify_event
    self.callbacks.process(s, event)
  File "C:\Python25\lib\site-packages\matplotlib\cbook.py", line 155, in process
    func(*args, **kwargs)
  File "C:\Python25\lib\site-packages\matplotlib\backend_bases.py", line 1894, in mouse_move
    try: s = event.inaxes.format_coord(event.xdata, event.ydata)
  File "C:\Python25\lib\site-packages\matplotlib\axes.py", line 2368, in format_coord
    xs = self.format_xdata(x)
  File "C:\Python25\lib\site-packages\matplotlib\axes.py", line 2348, in format_xdata
    val = func(x)
  File "C:\Python25\lib\site-packages\matplotlib\ticker.py", line 184, in format_data_short
    return self.format_data(value)
  File "C:\Python25\lib\site-packages\matplotlib\ticker.py", line 180, in format_data
    return self.__call__(value)
  File "C:\Python25\lib\site-packages\scikits\timeseries\lib\plotlib.py", line 783, in __call__
    return Date(self.freq, value=int(x)).strftime(fmt)
TypeError: strftime(fmt)() argument 1 must be string without null bytes, not str

Instead of the following in TimeSeries_DateFormatter in plotlib.py:

    def __call__(self, x, pos=0):
        if self.formatdict is None:
            return ''
        else:
            fmt = self.formatdict.pop(x, '')
            return Date(self.freq, value=int(x)).strftime(fmt)

The strftime function is trying to process a 'fmt' equal to an empty string. I think that if 'fmt' is an empty sting then the call should return an empty string and that seems to do the right thing. Something similar to the following:

    def __call__(self, x, pos=0):
        fmt = self.formatdict.pop(x, '')
        if self.formatdict is None or fmt == '':
            return ''
        else:
            return Date(self.freq, value=int(x)).strftime(fmt)

Sorry that it isn't a diff - don't quite know how to do that on Windows.

Kindest regards, Tim

Change History

Changed 10 months ago by timcera

I just realized that the previous fix isn't going to work right if self.formatdict is actually None.

    def __call__(self, x, pos=0):
        if self.formatdict is None:
            return ''
        fmt = self.formatdict.pop(x, '')
        if fmt == '':
            return ''
        else:
            return Date(self.freq, value=int(x)).strftime(fmt)

This I think is better, though my problem was that fmt was empty, not that self.formatdict was None, so I do not have a convenient way to test.

Kindest regards,

Tim

Changed 10 months ago by mattknox_ca

Hi Tim. Do you have a brief example demonstrating the error? I'd like to explore it a bit more.

Note: See TracTickets for help on using tickets.