Skip to content

Fix for issue 5575 along with testing #6091

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

Merged
merged 1 commit into from
Mar 13, 2016
Merged

Fix for issue 5575 along with testing #6091

merged 1 commit into from
Mar 13, 2016

Conversation

kylebsingh
Copy link

This is a pull request to resolve issue #5575.

Tracing calls made in plot_date() I realized it was ignoring timezones as a result of the axis being set while plotting, then trying to change the time zone.

In line 1427 of axis.py we have converter = munits.registry.get_converter(data). Unfortunately for setting the timezone the converter will be the same as when it was plotted originally. Thus in the following lines 1433-1435 we will not be able to set_units.

default = self.converter.default_units(data, self)
if default is not None and self.units is None:
    self.set_units(default)

My solution to this was to make sure that instead of the following in _axes.py's plot_data:

if xdate:
    self.xaxis_date(tz)
if ydate:
    self.yaxis_date(tz)

ret = self.plot(x, y, fmt, **kwargs)

we have:

ret = self.plot(x, y, fmt, **kwargs)
if xdate:
    self.xaxis_date(tz)
if ydate:
    self.yaxis_date(tz)

This ensures the plot has the correct timezone, and it also plots the correct data onto the plot.
I have added test cases to /lib/matplotlib/tests/test_axes which has tests for the same and different timezones in the x axis, y axis, and both the x and y axis

@tacaswell tacaswell added this to the 1.5.2 (Critical bug fix release) milestone Mar 2, 2016
@tacaswell
Copy link
Member

Can you add only png tests for this (and re-base the pdf/svg tests out of existence)? The reason is to keep the size of the repo down and to keep the tests as fast as possible. There is nothing backend dependent about this so testing it only on Agg should be enough.

Other wise 👍

It is great when problems have simple fixes!

Can you also put the explanation of why this fixed the problem in the commit message?

@kylebsingh
Copy link
Author

Done. Let me know if I missed anything in the pull request/commit.

@tacaswell
Copy link
Member

Can you rebase this to only one commit? Currently the svg/pdf are still in the history which means they are (forever) in the repository.

@tacaswell
Copy link
Member

If you just keep pu

@tacaswell
Copy link
Member

If you just keep (force) pushing to this branch github will 'do the right thing'. PRs track branches, not commits.

extensions=['png'])
def test_date_timezone_x():
#Tests issue 5575
time_index = [pytz.timezone('Canada/Eastern').localize(datetime.datetime(year=2016, month=2, day=22, hour=x)) for x in range(3)]
Copy link
Member

Choose a reason for hiding this comment

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

This line is too long; it should be wrapped at 79 characters.

… updates the units with the right timezone, before actually plotting the dates. Includes tests to ensure consistency and correctness
@kylebsingh
Copy link
Author

Sorry about earlier, I mis-clicked "Close and comment" instead of "comment". I have rebased and made the pep8 changes that I admittedly forgot to do. Thank you

@tacaswell tacaswell merged commit e47bc04 into matplotlib:master Mar 13, 2016
tacaswell added a commit that referenced this pull request Mar 13, 2016
FIX: plot_date ignores timezone

Closes #5575

Conflicts:
	lib/matplotlib/tests/test_axes.py

	   multiple PRs added tests at same location in file
	   keep all.
tacaswell added a commit that referenced this pull request Mar 13, 2016
FIX: plot_date ignores timezone

Closes #5575

Conflicts:
	lib/matplotlib/tests/test_axes.py

	   multiple PRs added tests at same location in file
	   keep all.
@tacaswell
Copy link
Member

merged locally to resolve minor conflict ee1a98c

backported to v1.5.x as 44afc73

tacaswell added a commit to tacaswell/matplotlib that referenced this pull request May 22, 2016
FIX: plot_date ignores timezone

Closes matplotlib#5575

Conflicts:
	lib/matplotlib/tests/test_axes.py

	   multiple PRs added tests at same location in file
	   keep all.
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.

4 participants