Skip to content

Commit

Permalink
BUG: don't copy int64 arrays in DatetimeIndex ctor when copy=False, c…
Browse files Browse the repository at this point in the history
…lose #1624
  • Loading branch information
wesm committed Jul 15, 2012
1 parent 5a64a12 commit dcd3c57
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions RELEASE.rst
Expand Up @@ -29,6 +29,7 @@ pandas 0.8.1

**New features**

- Add vectorized, NA-friendly string methods to Series (#1621, #620)
- Can pass dict of per-column line styles to DataFrame.plot (#1559)
- Add new ``bootstrap_plot`` plot function
- Add new ``parallel_coordinates`` plot function (#1488)
Expand Down Expand Up @@ -82,6 +83,7 @@ pandas 0.8.1
- Fix unit test errors on Python 3 (#1550)
- Fix .ix indexing bugs in duplicate DataFrame index (#1201)
- Better handle errors with non-existing objects in HDFStore (#1254)
- Don't copy int64 array data in DatetimeIndex when copy=False (#1624)

pandas 0.8.0
============
Expand Down
5 changes: 4 additions & 1 deletion pandas/tseries/index.py
Expand Up @@ -208,7 +208,10 @@ def __new__(cls, data=None,
else:
subarr = data
elif data.dtype == _INT64_DTYPE:
subarr = np.asarray(data, dtype=_NS_DTYPE)
if copy:
subarr = np.asarray(data, dtype=_NS_DTYPE)
else:
subarr = data.view(_NS_DTYPE)
else:
subarr = tools.to_datetime(data)
if not np.issubdtype(subarr.dtype, np.datetime64):
Expand Down
13 changes: 13 additions & 0 deletions pandas/tseries/tests/test_timeseries.py
Expand Up @@ -1012,6 +1012,19 @@ def test_datetimeindex_repr_short(self):
dr = date_range(start='1/1/2012', periods=3)
repr(dr)

def test_constructor_int64_nocopy(self):
# #1624
arr = np.arange(1000)
index = DatetimeIndex(arr)

arr[50:100] = -1
self.assert_((index.asi8[50:100] == -1).all())

arr = np.arange(1000)
index = DatetimeIndex(arr, copy=True)

arr[50:100] = -1
self.assert_((index.asi8[50:100] != -1).all())

def _simple_ts(start, end, freq='D'):
rng = date_range(start, end, freq=freq)
Expand Down

0 comments on commit dcd3c57

Please sign in to comment.