Skip to content

Commit d31e05f

Browse files
committed
Merge pull request #3138 from jreback/GH3042
BUG: GH3042 Timestamp now supports classmethod fromordinal similar to datetimes
2 parents ad6661b + 1cfa6d3 commit d31e05f

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

RELEASE.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ pandas 0.11.0
113113
df = DataFrame(dict(A = ts))
114114
df['2001']
115115
116-
117116
**API Changes**
118117

119118
- Do not automatically upcast numeric specified dtypes to ``int64`` or
@@ -220,7 +219,10 @@ pandas 0.11.0
220219
- Allow selection in an *unordered* timeseries to work similary
221220
to an *ordered* timeseries (GH2437_).
222221
- Fix implemented ``.xs`` when called with ``axes=1`` and a level parameter (GH2903_)
222+
- Timestamp now supports the class method fromordinal similar to datetimes (GH3042_)
223223

224+
.. _GH622: https://github.com/pydata/pandas/issues/622
225+
.. _GH797: https://github.com/pydata/pandas/issues/797
224226
.. _GH2758: https://github.com/pydata/pandas/issues/2758
225227
.. _GH2809: https://github.com/pydata/pandas/issues/2809
226228
.. _GH2810: https://github.com/pydata/pandas/issues/2810
@@ -236,8 +238,6 @@ pandas 0.11.0
236238
.. _GH2807: https://github.com/pydata/pandas/issues/2807
237239
.. _GH2918: https://github.com/pydata/pandas/issues/2918
238240
.. _GH3011: https://github.com/pydata/pandas/issues/3011
239-
.. _GH622: https://github.com/pydata/pandas/issues/622
240-
.. _GH797: https://github.com/pydata/pandas/issues/797
241241
.. _GH2681: https://github.com/pydata/pandas/issues/2681
242242
.. _GH2719: https://github.com/pydata/pandas/issues/2719
243243
.. _GH2746: https://github.com/pydata/pandas/issues/2746
@@ -267,19 +267,20 @@ pandas 0.11.0
267267
.. _GH2967: https://github.com/pydata/pandas/issues/2967
268268
.. _GH2982: https://github.com/pydata/pandas/issues/2982
269269
.. _GH2989: https://github.com/pydata/pandas/issues/2989
270+
.. _GH2993: https://github.com/pydata/pandas/issues/2993
270271
.. _GH3002: https://github.com/pydata/pandas/issues/3002
271272
.. _GH3010: https://github.com/pydata/pandas/issues/3010
272273
.. _GH3012: https://github.com/pydata/pandas/issues/3012
273274
.. _GH3029: https://github.com/pydata/pandas/issues/3029
274275
.. _GH3037: https://github.com/pydata/pandas/issues/3037
275276
.. _GH3041: https://github.com/pydata/pandas/issues/3041
277+
.. _GH3042: https://github.com/pydata/pandas/issues/3042
276278
.. _GH3053: https://github.com/pydata/pandas/issues/3053
279+
.. _GH3070: https://github.com/pydata/pandas/issues/3070
277280
.. _GH3076: https://github.com/pydata/pandas/issues/3076
278281
.. _GH3063: https://github.com/pydata/pandas/issues/3063
279282
.. _GH3059: https://github.com/pydata/pandas/issues/3059
280-
.. _GH2993: https://github.com/pydata/pandas/issues/2993
281283
.. _GH3115: https://github.com/pydata/pandas/issues/3115
282-
.. _GH3070: https://github.com/pydata/pandas/issues/3070
283284
.. _GH3130: https://github.com/pydata/pandas/issues/3130
284285

285286
pandas 0.10.1

pandas/tseries/tests/test_timeseries.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,19 @@ def test_timestamp_repr(self):
12621262
result = repr(stamp)
12631263
self.assert_(iso8601 in result)
12641264

1265+
def test_timestamp_from_ordinal(self):
1266+
1267+
# GH 3042
1268+
dt = datetime(2011, 4, 16, 0, 0)
1269+
ts = Timestamp.fromordinal(dt.toordinal())
1270+
self.assert_(ts.to_pydatetime() == dt)
1271+
1272+
# with a tzinfo
1273+
stamp = Timestamp('2011-4-16', tz='US/Eastern')
1274+
dt_tz = stamp.to_pydatetime()
1275+
ts = Timestamp.fromordinal(dt_tz.toordinal(),tz='US/Eastern')
1276+
self.assert_(ts.to_pydatetime() == dt_tz)
1277+
12651278
def test_datetimeindex_integers_shift(self):
12661279
rng = date_range('1/1/2000', periods=20)
12671280

pandas/tslib.pyx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ def _is_fixed_offset(tz):
120120
# This serves as the box for datetime64
121121
class Timestamp(_Timestamp):
122122

123+
@classmethod
124+
def fromordinal(cls, ordinal, offset=None, tz=None):
125+
""" passed an ordinal, translate and convert to a ts
126+
note: by definition there cannot be any tz info on the ordinal itself """
127+
return cls(datetime.fromordinal(ordinal),offset=offset,tz=tz)
128+
123129
def __new__(cls, object ts_input, object offset=None, tz=None):
124130
cdef _TSObject ts
125131
cdef _Timestamp ts_base

0 commit comments

Comments
 (0)