Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Expire deprecations in dates and ticker #24128

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
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions doc/api/next_api_changes/removals/24128-OG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
``epoch2num`` and ``num2epoch`` are removed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

These methods convert from unix timestamps to matplotlib floats, but are not
used internally to Matplotlib, and should not be needed by end users. To
convert a unix timestamp to datetime, simply use
`datetime.datetime.utcfromtimestamp`, or to use NumPy `~numpy.datetime64`
``dt = np.datetime64(e*1e6, 'us')``.


Locator and Formatter wrapper methods
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The ``set_view_interval``, ``set_data_interval`` and ``set_bounds`` methods of
`.Locator`\s and `.Formatter`\s (and their common base class, TickHelper) are
removed. Directly manipulate the view and data intervals on the underlying
axis instead.
4 changes: 2 additions & 2 deletions doc/api/prev_api_changes/api_changes_3.3.0/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ experimental and may change in the future.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... is deprecated.

`.epoch2num` and `.num2epoch` are deprecated
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``epoch2num`` and ``num2epoch`` are deprecated
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
These are unused and can be easily reproduced by other date tools.
`.get_epoch` will return Matplotlib's epoch.

Expand Down
2 changes: 1 addition & 1 deletion doc/api/prev_api_changes/api_changes_3.3.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ reverts the deprecation.
Functions ``epoch2num`` and ``dates.julian2num`` use ``date.epoch`` rcParam
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Now `~.dates.epoch2num` and (undocumented) ``julian2num`` return floating point
Now ``epoch2num`` and (undocumented) ``julian2num`` return floating point
days since `~.dates.get_epoch` as set by :rc:`date.epoch`, instead of
floating point days since the old epoch of "0000-12-31T00:00:00". If
needed, you can translate from the new to old values as
Expand Down
63 changes: 3 additions & 60 deletions lib/matplotlib/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,9 @@
from matplotlib import _api, cbook, ticker, units

__all__ = ('datestr2num', 'date2num', 'num2date', 'num2timedelta', 'drange',
'epoch2num', 'num2epoch', 'set_epoch', 'get_epoch', 'DateFormatter',
'ConciseDateFormatter', 'AutoDateFormatter',
'DateLocator', 'RRuleLocator', 'AutoDateLocator', 'YearLocator',
'MonthLocator', 'WeekdayLocator',
'set_epoch', 'get_epoch', 'DateFormatter', 'ConciseDateFormatter',
'AutoDateFormatter', 'DateLocator', 'RRuleLocator',
'AutoDateLocator', 'YearLocator', 'MonthLocator', 'WeekdayLocator',
'DayLocator', 'HourLocator', 'MinuteLocator',
'SecondLocator', 'MicrosecondLocator',
'rrule', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU',
Expand Down Expand Up @@ -1737,16 +1736,6 @@ def set_axis(self, axis):
self._wrapped_locator.set_axis(axis)
return super().set_axis(axis)

@_api.deprecated("3.5", alternative="`.Axis.set_view_interval`")
def set_view_interval(self, vmin, vmax):
self._wrapped_locator.set_view_interval(vmin, vmax)
return super().set_view_interval(vmin, vmax)

@_api.deprecated("3.5", alternative="`.Axis.set_data_interval`")
def set_data_interval(self, vmin, vmax):
self._wrapped_locator.set_data_interval(vmin, vmax)
return super().set_data_interval(vmin, vmax)

def __call__(self):
# if no data have been set, this will tank with a ValueError
try:
Expand Down Expand Up @@ -1778,52 +1767,6 @@ def _get_interval(self):
return self._interval


@_api.deprecated(
"3.5",
alternative="``[date2num(datetime.utcfromtimestamp(t)) for t in e]`` or "
"numpy.datetime64 types")
def epoch2num(e):
"""
Convert UNIX time to days since Matplotlib epoch.

Parameters
----------
e : list of floats
Time in seconds since 1970-01-01.

Returns
-------
`numpy.array`
Time in days since Matplotlib epoch (see `~.dates.get_epoch()`).
"""

dt = (np.datetime64('1970-01-01T00:00:00', 's') -
np.datetime64(get_epoch(), 's')).astype(float)

return (dt + np.asarray(e)) / SEC_PER_DAY


@_api.deprecated("3.5", alternative="`num2date(e).timestamp()<.num2date>`")
def num2epoch(d):
"""
Convert days since Matplotlib epoch to UNIX time.

Parameters
----------
d : list of floats
Time in days since Matplotlib epoch (see `~.dates.get_epoch()`).

Returns
-------
`numpy.array`
Time in seconds since 1970-01-01.
"""
dt = (np.datetime64('1970-01-01T00:00:00', 's') -
np.datetime64(get_epoch(), 's')).astype(float)

return np.asarray(d) * SEC_PER_DAY - dt


@_api.deprecated("3.6", alternative="`AutoDateLocator` and `AutoDateFormatter`"
" or vendor the code")
def date_ticker_factory(span, tz=None, numticks=5):
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/pylab.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import matplotlib as mpl

from matplotlib.dates import (
date2num, num2date, datestr2num, drange, epoch2num,
num2epoch, DateFormatter, DateLocator,
date2num, num2date, datestr2num, drange, DateFormatter, DateLocator,
RRuleLocator, YearLocator, MonthLocator, WeekdayLocator, DayLocator,
HourLocator, MinuteLocator, SecondLocator, rrule, MO, TU, WE, TH, FR,
SA, SU, YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, SECONDLY,
Expand Down
13 changes: 0 additions & 13 deletions lib/matplotlib/tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1240,19 +1240,6 @@ def test_change_interval_multiples():
assert ax.get_xticklabels()[1].get_text() == 'Feb 01 2020'


def test_epoch2num():
with _api.suppress_matplotlib_deprecation_warning():
mdates._reset_epoch_test_example()
mdates.set_epoch('0000-12-31')
assert mdates.epoch2num(86400) == 719164.0
assert mdates.num2epoch(719165.0) == 86400 * 2
# set back to the default
mdates._reset_epoch_test_example()
mdates.set_epoch('1970-01-01T00:00:00')
assert mdates.epoch2num(86400) == 1.0
assert mdates.num2epoch(2.0) == 86400 * 2


def test_julian2num():
mdates._reset_epoch_test_example()
mdates.set_epoch('0000-12-31')
Expand Down
15 changes: 0 additions & 15 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,6 @@ def create_dummy_axis(self, **kwargs):
if self.axis is None:
self.axis = _DummyAxis(**kwargs)

@_api.deprecated("3.5", alternative="`.Axis.set_view_interval`")
def set_view_interval(self, vmin, vmax):
self.axis.set_view_interval(vmin, vmax)

@_api.deprecated("3.5", alternative="`.Axis.set_data_interval`")
def set_data_interval(self, vmin, vmax):
self.axis.set_data_interval(vmin, vmax)

@_api.deprecated(
"3.5",
alternative="`.Axis.set_view_interval` and `.Axis.set_data_interval`")
def set_bounds(self, vmin, vmax):
self.set_view_interval(vmin, vmax)
self.set_data_interval(vmin, vmax)


class Formatter(TickHelper):
"""
Expand Down