Skip to content

BUG: Casting tz-aware DatetimeIndex to object-dtype ndarray/Index #23524

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 17 commits into from
Nov 11, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
61ad510
BUG: fix and test offset comparison with non-offsets
jbrockmendel Nov 6, 2018
937541e
whatsnew note
jbrockmendel Nov 6, 2018
ca9e8af
Fix and test casting tz-aware datetimeindex to object-dtype ndarray o…
jbrockmendel Nov 6, 2018
9d0fbd7
add GH references
jbrockmendel Nov 6, 2018
dbf145f
Clarify comment
jbrockmendel Nov 6, 2018
ec696e5
Merge branch 'master' of https://github.com/pandas-dev/pandas into in…
jbrockmendel Nov 6, 2018
8853b6a
test for np.array(arr, dtype=np.int64)
jbrockmendel Nov 6, 2018
9add480
release note for fixing dropping of nanoseconds
jbrockmendel Nov 6, 2018
cfd8e71
test for copy=False being respected
jbrockmendel Nov 7, 2018
bc06a61
Merge branch 'master' of https://github.com/pandas-dev/pandas into in…
jbrockmendel Nov 7, 2018
c9a2c22
Merge branch 'master' of https://github.com/pandas-dev/pandas into in…
jbrockmendel Nov 7, 2018
b4ecfbb
fix missing backticks
jbrockmendel Nov 7, 2018
756574f
comments
jbrockmendel Nov 7, 2018
ebada17
Merge branch 'master' of https://github.com/pandas-dev/pandas into in…
jbrockmendel Nov 8, 2018
bf1677a
move whatsnew note, do astype differently
jbrockmendel Nov 8, 2018
0a5dbed
remove comment
jbrockmendel Nov 9, 2018
cc7f5cd
Merge branch 'master' of https://github.com/pandas-dev/pandas into in…
jbrockmendel Nov 9, 2018
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
Next Next commit
move whatsnew note, do astype differently
  • Loading branch information
jbrockmendel committed Nov 8, 2018
commit bf1677addae30c468ab316291fc7637b8273c83a
6 changes: 3 additions & 3 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,9 @@ Datetimelike
- Bug in :class:`PeriodIndex` with attribute ``freq.n`` greater than 1 where adding a :class:`DateOffset` object would return incorrect results (:issue:`23215`)
- Bug in :class:`Series` that interpreted string indices as lists of characters when setting datetimelike values (:issue:`23451`)
- Bug in :class:`Timestamp` constructor which would drop the frequency of an input :class:`Timestamp` (:issue:`22311`)
- Bug in :class:`DatetimeIndex` where calling ``np.array(dtindex, dtype=object)`` would incorrectly return an array of ``long`` objects (:issue:`23524`)
- Bug in :class:`Index` where passing a timezone-aware :class:`DatetimeIndex` and `dtype=object` would incorrectly raise a ``ValueError`` (:issue:`23524`)
- Bug in :class:`Index` where calling ``np.array(dtindex, dtype=object)`` on a timezone-naive :class:`DatetimeIndex` would return an array of ``datetime`` objects instead of :class:`Timestamp` objects, potentially losing nanosecond portions of the timestamps (:issue:`23524`)

Timedelta
^^^^^^^^^
Expand Down Expand Up @@ -1373,6 +1376,3 @@ Other
- :meth:`~pandas.io.formats.style.Styler.bar` now also supports tablewise application (in addition to rowwise and columnwise) with ``axis=None`` and setting clipping range with ``vmin`` and ``vmax`` (:issue:`21548` and :issue:`21526`). ``NaN`` values are also handled properly.
- Logical operations ``&, |, ^`` between :class:`Series` and :class:`Index` will no longer raise ``ValueError`` (:issue:`22092`)
- Bug in :meth:`DataFrame.combine_first` in which column types were unexpectedly converted to float (:issue:`20699`)
- Bug in :class:`Index` where passing a timezone-aware :class:`DatetimeIndex` and `dtype=object` would incorrectly raise a ``ValueError`` (:issue:`23524`)
- Bug in :class:`DatetimeIndex` where calling ``np.array(dtindex, dtype=object)`` would incorrectly return an array of ``long`` objects (:issue:`23524`)
- Bug in :class:`Index` where calling ``np.array(dtindex, dtype=object)`` on a timezone-naive :class:`DatetimeIndex` would return an array of ``datetime`` objects instead of :class:`Timestamp` objects, potentially losing nanosecond portions of the timestamps (:issue:`23524`)
6 changes: 4 additions & 2 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,10 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None,
# will raise in the where `data` is already tz-aware. So
# we leave it out of this step and cast to object-dtype after
# the DatetimeIndex construction.
result = DatetimeIndex(data, copy=copy, name=name, **kwargs)
return Index(list(result), dtype=_o_dtype)
# Note we can pass copy=False because the .astype below
# will always make a copy
result = DatetimeIndex(data, copy=False, name=name, **kwargs)
return result.astype(object)
else:
result = DatetimeIndex(data, copy=copy, name=name,
dtype=dtype, **kwargs)
Expand Down