File tree 3 files changed +51
-7
lines changed
doc/api/next_api_changes/deprecations
3 files changed +51
-7
lines changed 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):
1750
1750
return self ._interval
1751
1751
1752
1752
1753
- @cbook .deprecated ("3.3" )
1754
1753
def epoch2num (e ):
1755
1754
"""
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()`).
1758
1766
"""
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
1760
1772
1761
1773
1762
- @cbook .deprecated ("3.3" )
1763
1774
def num2epoch (d ):
1764
1775
"""
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.
1766
1787
"""
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
1768
1792
1769
1793
1770
1794
@cbook .deprecated ("3.2" )
Original file line number Diff line number Diff line change @@ -998,3 +998,15 @@ def test_change_interval_multiples():
998
998
fig .canvas .draw ()
999
999
assert ax .get_xticklabels ()[0 ].get_text () == 'Jan 15 2020'
1000
1000
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