Skip to content

Commit 7dbcb4c

Browse files
committed
Merge branch 'master' of github.com:pydata/pandas
2 parents e02bd54 + 48e1149 commit 7dbcb4c

File tree

4 files changed

+68
-9
lines changed

4 files changed

+68
-9
lines changed

doc/source/categorical.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ Comparisons
356356
Comparing categorical data with other objects is possible in three cases:
357357

358358
* comparing equality (``==`` and ``!=``) to a list-like object (list, Series, array,
359-
...) of the same length as the categorical data or
359+
...) of the same length as the categorical data.
360360
* all comparisons (``==``, ``!=``, ``>``, ``>=``, ``<``, and ``<=``) of categorical data to
361-
another categorical Series, when ``ordered==True`` and the `categories` are the same or
361+
another categorical Series, when ``ordered==True`` and the `categories` are the same.
362362
* all comparisons of a categorical data to a scalar.
363363

364364
All other comparisons, especially "non-equality" comparisons of two categoricals with different
@@ -392,7 +392,8 @@ Equality comparisons work with any list-like object of same length and scalars:
392392

393393
.. ipython:: python
394394
395-
cat == cat_base2
395+
cat == cat_base
396+
cat == np.array([1,2,3])
396397
cat == 2
397398
398399
This doesn't work because the categories are not the same:

doc/source/whatsnew/v0.15.2.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ API changes
9191
data.y
9292
data['y'].values
9393

94+
- Timestamp('now') is now equivalent to Timestamp.now() in that it returns the local time rather than UTC. Also, Timestamp('today') is now
95+
equivalent to Timestamp.today() and both have tz as a possible argument. (:issue:`9000`)
96+
9497
.. _whatsnew_0152.enhancements:
9598

9699
Enhancements

pandas/tseries/tests/test_tslib.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,36 @@ def test_barely_oob_dts(self):
301301
def test_utc_z_designator(self):
302302
self.assertEqual(get_timezone(Timestamp('2014-11-02 01:00Z').tzinfo), 'UTC')
303303

304+
def test_now(self):
305+
# #9000
306+
ts_from_string = Timestamp('now')
307+
ts_from_method = Timestamp.now()
308+
ts_datetime = datetime.datetime.now()
309+
310+
ts_from_string_tz = Timestamp('now', tz='US/Eastern')
311+
ts_from_method_tz = Timestamp.now(tz='US/Eastern')
312+
313+
# Check that the delta between the times is less than 1s (arbitrarily small)
314+
delta = Timedelta(seconds=1)
315+
self.assertTrue((ts_from_method - ts_from_string) < delta)
316+
self.assertTrue((ts_from_method_tz - ts_from_string_tz) < delta)
317+
self.assertTrue((ts_from_string_tz.tz_localize(None) - ts_from_string) < delta)
318+
319+
def test_today(self):
320+
321+
ts_from_string = Timestamp('today')
322+
ts_from_method = Timestamp.today()
323+
ts_datetime = datetime.datetime.today()
324+
325+
ts_from_string_tz = Timestamp('today', tz='US/Eastern')
326+
ts_from_method_tz = Timestamp.today(tz='US/Eastern')
327+
328+
# Check that the delta between the times is less than 1s (arbitrarily small)
329+
delta = Timedelta(seconds=1)
330+
self.assertTrue((ts_from_method - ts_from_string) < delta)
331+
self.assertTrue((ts_datetime - ts_from_method) < delta)
332+
self.assertTrue((ts_datetime - ts_from_method) < delta)
333+
self.assertTrue((ts_from_string_tz.tz_localize(None) - ts_from_string) < delta)
304334

305335
class TestDatetimeParsingWrappers(tm.TestCase):
306336
def test_does_not_convert_mixed_integer(self):

pandas/tslib.pyx

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ def ints_to_pytimedelta(ndarray[int64_t] arr, box=False):
176176
result[i] = NaT
177177
else:
178178
if box:
179-
result[i] = Timedelta(value)
179+
result[i] = Timedelta(value)
180180
else:
181-
result[i] = timedelta(microseconds=int(value)/1000)
181+
result[i] = timedelta(microseconds=int(value)/1000)
182182

183183
return result
184184

@@ -219,15 +219,32 @@ class Timestamp(_Timestamp):
219219

220220
@classmethod
221221
def now(cls, tz=None):
222-
""" compat now with datetime """
222+
"""
223+
Return the current time in the local timezone. Equivalent
224+
to datetime.now([tz])
225+
226+
Parameters
227+
----------
228+
tz : string / timezone object, default None
229+
Timezone to localize to
230+
"""
223231
if isinstance(tz, basestring):
224232
tz = maybe_get_tz(tz)
225233
return cls(datetime.now(tz))
226234

227235
@classmethod
228-
def today(cls):
229-
""" compat today with datetime """
230-
return cls(datetime.today())
236+
def today(cls, tz=None):
237+
"""
238+
Return the current time in the local timezone. This differs
239+
from datetime.today() in that it can be localized to a
240+
passed timezone.
241+
242+
Parameters
243+
----------
244+
tz : string / timezone object, default None
245+
Timezone to localize to
246+
"""
247+
return cls.now(tz)
231248

232249
@classmethod
233250
def utcnow(cls):
@@ -1024,6 +1041,14 @@ cdef convert_to_tsobject(object ts, object tz, object unit):
10241041
if util.is_string_object(ts):
10251042
if ts in _nat_strings:
10261043
ts = NaT
1044+
elif ts == 'now':
1045+
# Issue 9000, we short-circuit rather than going
1046+
# into np_datetime_strings which returns utc
1047+
ts = Timestamp.now(tz)
1048+
elif ts == 'today':
1049+
# Issue 9000, we short-circuit rather than going
1050+
# into np_datetime_strings which returns a normalized datetime
1051+
ts = Timestamp.today(tz)
10271052
else:
10281053
try:
10291054
_string_to_dts(ts, &obj.dts, &out_local, &out_tzoffset)

0 commit comments

Comments
 (0)