File tree Expand file tree Collapse file tree
doc/api/next_api_changes/deprecations Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Reverted deprecation of `~.dates.num2epoch ` and `~.dates.epoch2num `
2+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+ These two functions were deprecated in 3.3.0, and did not return
5+ an accurate Matplotlib datenum relative to the new Matplotlib epoch
6+ handling (`~.dates.get_epoch ` and :rc: `date.epoch `). This version
7+ reverts the deprecation and fixes those functions to work with
8+ `~.dates.get_epoch `.
Original file line number Diff line number Diff line change @@ -1750,21 +1750,45 @@ def _get_interval(self):
17501750 return self ._interval
17511751
17521752
1753- @cbook .deprecated ("3.3" )
17541753def epoch2num (e ):
17551754 """
1756- Convert an epoch or sequence of epochs to the new date format,
1757- that is days since 0001.
1755+ Convert UNIX time to days since Matplotlib epoch.
1756+
1757+ Parameters
1758+ ----------
1759+ e : list of floats
1760+ Time in seconds since 1970-01-01.
1761+
1762+ Returns
1763+ -------
1764+ `numpy.array`
1765+ Time in days since Matplotlib epoch (see `~.dates.get_epoch()`).
17581766 """
1759- return EPOCH_OFFSET + np .asarray (e ) / SEC_PER_DAY
1767+
1768+ dt = (np .datetime64 ('1970-01-01T00:00:00' , 's' ) -
1769+ np .datetime64 (get_epoch (), 's' )).astype (float )
1770+
1771+ return (dt + np .asarray (e )) / SEC_PER_DAY
17601772
17611773
1762- @cbook .deprecated ("3.3" )
17631774def num2epoch (d ):
17641775 """
1765- Convert days since 0001 to epoch. *d* can be a number or sequence.
1776+ Convert days since Matplotlib epoch to UNIX time.
1777+
1778+ Parameters
1779+ ----------
1780+ d : list of floats
1781+ Time in days since Matplotlib epoch (see `~.dates.get_epoch()`).
1782+
1783+ Returns
1784+ -------
1785+ `numpy.array`
1786+ Time in seconds since 1970-01-01.
17661787 """
1767- return (np .asarray (d ) - EPOCH_OFFSET ) * SEC_PER_DAY
1788+ dt = (np .datetime64 ('1970-01-01T00:00:00' , 's' ) -
1789+ np .datetime64 (get_epoch (), 's' )).astype (float )
1790+
1791+ return np .asarray (d ) * SEC_PER_DAY - dt
17681792
17691793
17701794@cbook .deprecated ("3.2" )
Original file line number Diff line number Diff line change @@ -998,3 +998,15 @@ def test_change_interval_multiples():
998998 fig .canvas .draw ()
999999 assert ax .get_xticklabels ()[0 ].get_text () == 'Jan 15 2020'
10001000 assert ax .get_xticklabels ()[1 ].get_text () == 'Feb 01 2020'
1001+
1002+
1003+ def test_epoch2num ():
1004+ mdates ._reset_epoch_test_example ()
1005+ mdates .set_epoch ('0000-12-31' )
1006+ assert mdates .epoch2num (86400 ) == 719164.0
1007+ assert mdates .num2epoch (719165.0 ) == 86400 * 2
1008+ # set back to the default
1009+ mdates ._reset_epoch_test_example ()
1010+ mdates .set_epoch ('1970-01-01T00:00:00' )
1011+ assert mdates .epoch2num (86400 ) == 1.0
1012+ assert mdates .num2epoch (2.0 ) == 86400 * 2
You can’t perform that action at this time.
0 commit comments