Skip to content

Commit cc44795

Browse files
committed
ENH: can pass valid pytz timezone name to date_range, DatetimeIndex close #1089
1 parent eba54e9 commit cc44795

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

pandas/core/datetools.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ def to_datetime(arg, errors='ignore', dayfirst=False):
9090
raise_=errors == 'raise',
9191
dayfirst=dayfirst)
9292
return Series(values, index=arg.index, name=arg.name)
93-
elif isinstance(arg, np.ndarray):
93+
elif isinstance(arg, (np.ndarray, list)):
94+
if isinstance(arg, list):
95+
arg = np.array(arg, dtype='O')
9496
return lib.string_to_datetime(com._ensure_object(arg),
9597
raise_=errors == 'raise',
9698
dayfirst=dayfirst)
@@ -2216,6 +2218,10 @@ def _figure_out_timezone(start, end, tzinfo):
22162218
assert(inferred_tz == tzinfo)
22172219
# make tz naive for now
22182220

2221+
if isinstance(tz, (str, unicode)):
2222+
import pytz
2223+
tz = pytz.timezone(tz)
2224+
22192225
start = start if start is None else start.replace(tzinfo=None)
22202226
end = end if end is None else end.replace(tzinfo=None)
22212227

pandas/core/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ def __new__(cls, data=None,
12281228
"please use 'freq' instead",
12291229
FutureWarning)
12301230
if isinstance(freq, basestring):
1231-
freq = datetools.getOffset(freq)
1231+
freq = datetools.get_offset(freq)
12321232
else:
12331233
if isinstance(freq, basestring):
12341234
freq = datetools.to_offset(freq)

pandas/tests/test_timeseries.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,14 @@ def test_asobject_tz_box(self):
877877
result = index.asobject
878878
self.assert_(result[0].tz is tz)
879879

880+
def test_tz_string(self):
881+
_skip_if_no_pytz()
882+
result = date_range('1/1/2000', periods=10, tz='US/Eastern')
883+
expected = date_range('1/1/2000', periods=10,
884+
tz=pytz.timezone('US/Eastern'))
885+
886+
self.assert_(result.equals(expected))
887+
880888
def test_datetimeindex_constructor(self):
881889
arr = ['1/1/2005', '1/2/2005', 'Jn 3, 2005', '2005-01-04']
882890
self.assertRaises(Exception, DatetimeIndex, arr)

0 commit comments

Comments
 (0)