Skip to content

VIS: test plots losing information on y axis #26676

Open
@jbrockmendel

Description

@jbrockmendel

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions