Skip to content

API: consistent __array__ for datetime-like ExtensionArrays #23593

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 18 commits into from
Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Merge remote-tracking branch 'upstream/master' into jorisvandenbossch…
…e-ea-array-protocol
  • Loading branch information
TomAugspurger committed Jan 5, 2019
commit 4120586e626a4d3815a7f69132af70429a54dea8
7 changes: 7 additions & 0 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,13 @@ def _resolution(self):
# ----------------------------------------------------------------
# Array-Like / EA-Interface Methods

def __array__(self, dtype=None):
if dtype is None and self.tz:
# The default for tz-aware is object, to preserve tz info
dtype = object

return super(DatetimeArray, self).__array__(dtype=dtype)

def __iter__(self):
"""
Return an iterator over the boxed values
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/arrays/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def test_array_interface(self, datetime_index):
assert result is expected
tm.assert_numpy_array_equal(result, expected)
result = np.array(arr, dtype='datetime64[ns]')
assert not result is expected
assert result is not expected
tm.assert_numpy_array_equal(result, expected)

# to object dtype
Expand Down Expand Up @@ -538,7 +538,7 @@ def test_array_interface(self, timedelta_index):
assert result is expected
tm.assert_numpy_array_equal(result, expected)
result = np.array(arr, dtype='timedelta64[ns]')
assert not result is expected
assert result is not expected
tm.assert_numpy_array_equal(result, expected)

# to object dtype
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.