Skip to content

VIS: test plots losing information on y axis #26676

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

Open
jbrockmendel opened this issue Jun 5, 2019 · 2 comments
Open

VIS: test plots losing information on y axis #26676

jbrockmendel opened this issue Jun 5, 2019 · 2 comments
Labels
Bug Timezones Timezone data dtype Visualization plotting

Comments

@jbrockmendel
Copy link
Member

tests.plotting.test_frame.TestDataFramePlots.test_subplots_timeseries_y_axis issues a warning when plotting a datetime64[tz] column:

pandas/tests/plotting/test_frame.py::TestDataFramePlots::test_subplots_timeseries_y_axis
  /Users/bmendel/Desktop/pd/matwarns/pandas/plotting/_core.py:384: FutureWarning: Converting timezone-aware DatetimeArray to timezone-naive ndarray with 'datetime64[ns]' dtype. In the future, this will return an ndarray with 'object' dtype where each element is a 'pandas.Timestamp' with the correct 'tz'.
  	To accept the future behavior, pass 'dtype=object'.
  	To keep the old behavior, pass 'dtype="datetime64[ns]"'.
    numeric_data[col] = np.asarray(numeric_data[col])

The relevant code is:

data = {"numeric": np.array([1, 2, 5]),
                "timedelta": [pd.Timedelta(-10, unit="s"),
                              pd.Timedelta(10, unit="m"),
                              pd.Timedelta(10, unit="h")],
                "datetime_no_tz": [pd.to_datetime("2017-08-01 00:00:00"),
                                   pd.to_datetime("2017-08-01 02:00:00"),
                                   pd.to_datetime("2017-08-02 00:00:00")],
                "datetime_all_tz": [pd.to_datetime("2017-08-01 00:00:00",
                                                   utc=True),
                                    pd.to_datetime("2017-08-01 02:00:00",
                                                   utc=True),
                                    pd.to_datetime("2017-08-02 00:00:00",
                                                   utc=True)],
                "text": ["This", "should", "fail"]}

testdata = pd.DataFrame(data)

ax_datetime_no_tz = testdata.plot(y="datetime_no_tz")
ax_datetime_all_tz = testdata.plot(y="datetime_all_tz")

Checking the actual images generated by these last two:
ax_datetime_all_tz
ax_datetime_no_tz

The UTC is completely lost for the tz-aware case, and in both cases the dates are rendered without year and with weird-looking hour.

@dstansby
Copy link
Contributor

  • The axis formatting is the default Matplotlib datetime formatting, which is currently "3 significant bits", so in this case month-day hour. In this case it isn't the best, but I think it plays nicely with different zoom levels. Suggestions for improvements welcome on the Matplotlib bug tracker!
  • I think the warning is being emitted by numpy? The call np.asarray() is trying to cast some timezone aware stuff to np.datetime64, which I think is dropping timezone support soon.

@jklymak
Copy link
Contributor

jklymak commented Jul 19, 2019

You can also see https://matplotlib.org/3.1.0/gallery/ticks_and_spines/date_concise_formatter.html for formatting alternatives. Can't help w/ the timezone stuff!

@mroeschke mroeschke added Timezones Timezone data dtype Bug and removed Enhancement Testing pandas testing functions or related to the test suite labels Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timezones Timezone data dtype Visualization plotting
Projects
None yet
Development

No branches or pull requests

5 participants