File tree 3 files changed +52
-7
lines changed
3 files changed +52
-7
lines changed Original file line number Diff line number Diff line change 1
1
Deprecations
2
2
------------
3
+
4
+ Reverted deprecation of `~.dates.num2epoch ` and `~.dates.epoch2num `
5
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6
+
7
+ These two functions were deprecated in 3.3.0, and did not return
8
+ an accurate Matplotlib datenum relative to the new Matplotlib epoch
9
+ handling (`~.dates.get_epoch ` and :rc: `date.epoch `). This version
10
+ reverts the deprecation and fixes those functions to work with
11
+ `~.dates.get_epoch `.
Original file line number Diff line number Diff line change @@ -1752,21 +1752,45 @@ def _get_interval(self):
1752
1752
return self ._interval
1753
1753
1754
1754
1755
- @cbook .deprecated ("3.3" )
1756
1755
def epoch2num (e ):
1757
1756
"""
1758
- Convert an epoch or sequence of epochs to the new date format,
1759
- that is days since 0001.
1757
+ Convert UNIX time to days since Matplotlib epoch.
1758
+
1759
+ Parameters
1760
+ ----------
1761
+ e : list of floats
1762
+ Time in seconds since 1970-01-01.
1763
+
1764
+ Returns
1765
+ -------
1766
+ `numpy.array`
1767
+ Time in days since Matplotlib epoch (see `~.dates.get_epoch()`).
1760
1768
"""
1761
- return EPOCH_OFFSET + np .asarray (e ) / SEC_PER_DAY
1769
+
1770
+ dt = (np .datetime64 ('1970-01-01T00:00:00' , 's' ) -
1771
+ np .datetime64 (get_epoch (), 's' )).astype (float )
1772
+
1773
+ return (dt + np .asarray (e )) / SEC_PER_DAY
1762
1774
1763
1775
1764
- @cbook .deprecated ("3.3" )
1765
1776
def num2epoch (d ):
1766
1777
"""
1767
- Convert days since 0001 to epoch. *d* can be a number or sequence.
1778
+ Convert days since Matplotlib epoch to UNIX time.
1779
+
1780
+ Parameters
1781
+ ----------
1782
+ d : list of floats
1783
+ Time in days since Matplotlib epoch (see `~.dates.get_epoch()`).
1784
+
1785
+ Returns
1786
+ -------
1787
+ `numpy.array`
1788
+ Time in seconds since 1970-01-01.
1768
1789
"""
1769
- return (np .asarray (d ) - EPOCH_OFFSET ) * SEC_PER_DAY
1790
+ dt = (np .datetime64 ('1970-01-01T00:00:00' , 's' ) -
1791
+ np .datetime64 (get_epoch (), 's' )).astype (float )
1792
+
1793
+ return np .asarray (d ) * SEC_PER_DAY - dt
1770
1794
1771
1795
1772
1796
@cbook .deprecated ("3.2" )
Original file line number Diff line number Diff line change @@ -947,3 +947,15 @@ def test_change_epoch():
947
947
np .testing .assert_allclose (
948
948
mdates .date2num (np .datetime64 ('1970-01-01T12:00:00' )),
949
949
0.5 )
950
+
951
+
952
+ def test_epoch2num ():
953
+ mdates ._reset_epoch_test_example ()
954
+ mdates .set_epoch ('0000-12-31' )
955
+ assert mdates .epoch2num (86400 ) == 719164.0
956
+ assert mdates .num2epoch (719165.0 ) == 86400 * 2
957
+ # set back to the default
958
+ mdates ._reset_epoch_test_example ()
959
+ mdates .set_epoch ('1970-01-01T00:00:00' )
960
+ assert mdates .epoch2num (86400 ) == 1.0
961
+ assert mdates .num2epoch (2.0 ) == 86400 * 2
You can’t perform that action at this time.
0 commit comments