Skip to content

bits of 24364 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ def dt64arr_to_periodarr(data, freq, tz=None):

if not (is_datetime64_ns_dtype(data.dtype) or
is_datetime64tz_dtype(data.dtype)):
raise ValueError('Wrong dtype: %s' % data.dtype)
raise ValueError('Wrong dtype: {dtype}'.format(dtype=data.dtype))

if isinstance(data, ABCIndexClass):
if freq is None:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,11 +1437,11 @@ def date_range(start=None, end=None, periods=None, freq=None, tz=None,
if freq is None and com._any_none(periods, start, end):
freq = 'D'

result = DatetimeArray._generate_range(
dtarr = DatetimeArray._generate_range(
start=start, end=end, periods=periods,
freq=freq, tz=tz, normalize=normalize,
closed=closed, **kwargs)
return DatetimeIndex(result, name=name)
return DatetimeIndex(dtarr, name=name)


def bdate_range(start=None, end=None, periods=None, freq='B', tz=None,
Expand Down
8 changes: 5 additions & 3 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ def _join_i8_wrapper(joinf, **kwargs):
_object_ops = TimedeltaArray._object_ops
_field_ops = TimedeltaArray._field_ops
_datetimelike_ops = TimedeltaArray._datetimelike_ops
_datetimelike_methods = TimedeltaArray._datetimelike_methods
_other_ops = TimedeltaArray._other_ops

# -------------------------------------------------------------------
# Constructors
Expand Down Expand Up @@ -790,6 +792,6 @@ def timedelta_range(start=None, end=None, periods=None, freq=None,
freq = 'D'

freq, freq_infer = dtl.maybe_infer_freq(freq)
result = TimedeltaArray._generate_range(start, end, periods, freq,
closed=closed)
return TimedeltaIndex(result, name=name)
tdarr = TimedeltaArray._generate_range(start, end, periods, freq,
closed=closed)
return TimedeltaIndex(tdarr, name=name)
1 change: 1 addition & 0 deletions pandas/tests/arrays/test_timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_copy(self):

arr = TimedeltaArray(data, copy=True)
assert arr._data is not data
assert arr._data.base is not data


class TestTimedeltaArray(object):
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/indexes/datetimes/test_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import pytest
import pytz

from pandas._libs.tslib import OutOfBoundsDatetime
from pandas._libs.tslibs import conversion
from pandas._libs.tslibs import OutOfBoundsDatetime, conversion

import pandas as pd
from pandas import (
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/indexes/datetimes/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from pandas import (
DataFrame, DatetimeIndex, Index, NaT, Series, Timestamp, compat,
date_range, isna, to_datetime)
from pandas.core.arrays import DatetimeArrayMixin as DatetimeArray
from pandas.core.tools import datetimes as tools
from pandas.util import testing as tm
from pandas.util.testing import assert_series_equal
Expand Down Expand Up @@ -246,6 +247,18 @@ def test_to_datetime_parse_timezone_keeps_name(self):


class TestToDatetime(object):
@pytest.mark.parametrize('tz', [None, 'US/Central'])
def test_to_datetime_dtarr(self, tz):
# DatetimeArray
dti = date_range('1965-04-03', periods=19, freq='2W', tz=tz)
arr = DatetimeArray(dti)

result = to_datetime(arr)
assert result is arr

result = to_datetime(arr, box=True)
assert result is arr

def test_to_datetime_pydatetime(self):
actual = pd.to_datetime(datetime(2008, 1, 15))
assert actual == datetime(2008, 1, 15)
Expand Down