Skip to content
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

REF: DatetimeLikeArray #24024

Merged
merged 220 commits into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
220 commits
Select commit Hold shift + click to select a range
e9c8418
Squashed commit of the following:
TomAugspurger Nov 30, 2018
80d9576
Squashed commit of the following:
TomAugspurger Nov 30, 2018
acd5b6d
Squashed commit of the following:
TomAugspurger Nov 30, 2018
f364f77
REF: DatetimeArray
TomAugspurger Nov 30, 2018
56d9af6
fixup! REF: DatetimeArray
TomAugspurger Nov 30, 2018
538db1f
fixup! REF: DatetimeArray
TomAugspurger Nov 30, 2018
6620b0f
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 3, 2018
4842e53
fixup
TomAugspurger Dec 3, 2018
a7c1d42
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 3, 2018
07586d9
fixup
TomAugspurger Dec 3, 2018
7ebb9ee
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 4, 2018
e843984
REF: Move dispatched properties to array, not like
TomAugspurger Dec 4, 2018
67a9cf9
TST: Work around statsmodels bug (#24090)
TomAugspurger Dec 4, 2018
09837ac
fixups
TomAugspurger Dec 4, 2018
f3f9142
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 4, 2018
7c76b3e
fixups
TomAugspurger Dec 5, 2018
eae133d
fixups
TomAugspurger Dec 5, 2018
165f3fd
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 5, 2018
7ec7351
Squashed commit of the following:
TomAugspurger Dec 5, 2018
e7538e6
Fixed: where
TomAugspurger Dec 5, 2018
4f1ee37
revert constructor change
TomAugspurger Dec 5, 2018
a117de4
some cleanups
TomAugspurger Dec 5, 2018
1f463a1
Squashed commit of the following:
TomAugspurger Dec 6, 2018
d5fdc21
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 6, 2018
98182b1
Fixed IO pytables
TomAugspurger Dec 6, 2018
d4c9521
wip:constructor
TomAugspurger Dec 6, 2018
c22a30a
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 7, 2018
abd019a
Squashed commit of the following:
TomAugspurger Dec 7, 2018
4e9608e
Boxing compat
TomAugspurger Dec 7, 2018
4988630
test fixups
TomAugspurger Dec 7, 2018
3eb8432
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 7, 2018
2a562b8
Revert "Squashed commit of the following:"
TomAugspurger Dec 7, 2018
f4cbf36
hacky where fix
TomAugspurger Dec 7, 2018
b366968
basic unstack test
TomAugspurger Dec 7, 2018
fef6847
where fixups
TomAugspurger Dec 7, 2018
9c19b8c
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 7, 2018
3970f62
Cleanup
TomAugspurger Dec 7, 2018
9a50f92
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 8, 2018
ebb4009
unxfail
TomAugspurger Dec 8, 2018
57b401e
lint
TomAugspurger Dec 8, 2018
0a61ba8
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 9, 2018
323bfeb
clarify _values behavior
TomAugspurger Dec 9, 2018
2c1719f
remove xfail
TomAugspurger Dec 9, 2018
62bf6c6
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 10, 2018
0a8ccfd
[WIP]: Fixed groupby resample
TomAugspurger Dec 10, 2018
d5f2ac2
wip
TomAugspurger Dec 10, 2018
831d91a
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 10, 2018
e69ba08
EA-Where cleanup
TomAugspurger Dec 10, 2018
c31b80e
wip: remove wrap_array_method
TomAugspurger Dec 10, 2018
b4a0dc6
wip: more dispatching
TomAugspurger Dec 10, 2018
8c0641b
wip: py2 compat
TomAugspurger Dec 10, 2018
5d7dfda
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 10, 2018
580f7ba
old DTI pickle compat
TomAugspurger Dec 10, 2018
c41ec57
REF: TDA Constructor
TomAugspurger Dec 10, 2018
558adf8
WIP: Fix json serialization
TomAugspurger Dec 6, 2018
6586bcd
fixup! WIP: Fix json serialization
TomAugspurger Dec 11, 2018
5777ed0
TDA Constructor fixups
TomAugspurger Dec 11, 2018
d20291f
Constructors
TomAugspurger Dec 11, 2018
0f231e7
versionadded
TomAugspurger Dec 11, 2018
5f473df
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 11, 2018
c3b7dea
Ops updates
TomAugspurger Dec 11, 2018
074eed9
Cleanup
TomAugspurger Dec 11, 2018
02145d9
edge cases
TomAugspurger Dec 11, 2018
bf57186
fixups
TomAugspurger Dec 11, 2018
af34a0d
32-bit compat
TomAugspurger Dec 11, 2018
d557976
32-bit compat
TomAugspurger Dec 12, 2018
87f18e3
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 12, 2018
afc4c4a
Astype fixups
TomAugspurger Dec 12, 2018
3702801
doc comment
TomAugspurger Dec 12, 2018
119575f
32-bit compat
TomAugspurger Dec 12, 2018
0cd6958
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 12, 2018
4371ed0
TST: tighten up matches
TomAugspurger Dec 12, 2018
629e8e5
Add API breaking release notes
TomAugspurger Dec 12, 2018
a9a2101
Unique docstring
TomAugspurger Dec 12, 2018
4c460c6
py27, 64bit compat
TomAugspurger Dec 12, 2018
ac734b3
maybe fix 0.24 syntax
TomAugspurger Dec 12, 2018
b485e5a
Large cleanup
TomAugspurger Dec 12, 2018
f7d9cdb
BUG: Fixed DataFrame.values for 1 column DataFrame
TomAugspurger Dec 12, 2018
a86e4cb
Cleanup
TomAugspurger Dec 13, 2018
462a4f7
Hide one
TomAugspurger Dec 13, 2018
b901c3d
JSON comments
TomAugspurger Dec 13, 2018
4bf1862
Fixups
TomAugspurger Dec 13, 2018
7dd3ba5
Some cleanups
TomAugspurger Dec 13, 2018
87101bf
Fixup DatetimeTZBlock.get_values
TomAugspurger Dec 13, 2018
8c6f2db
Fixed datetimelike-max
TomAugspurger Dec 13, 2018
6bfd919
Document IncompatibleTimezoneError
TomAugspurger Dec 13, 2018
4cb6c50
Update concat test
TomAugspurger Dec 13, 2018
4c1609a
dispatch _to_json_values
TomAugspurger Dec 13, 2018
e7505cd
clarifying comments
TomAugspurger Dec 13, 2018
8060edd
Added check for ABCDatetimeArray & ABCPeriodArray
TomAugspurger Dec 13, 2018
55f6c26
Docstring for DatetimeTZDtype
TomAugspurger Dec 13, 2018
ef11a07
Use super for _add_delta
TomAugspurger Dec 13, 2018
17a3bbb
Remove redundant properties
TomAugspurger Dec 13, 2018
48f85f0
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 13, 2018
4ec0284
Dispatch tz, tzinfo
TomAugspurger Dec 13, 2018
aa82a0b
Updates
TomAugspurger Dec 13, 2018
d7dcd79
Added some docs
TomAugspurger Dec 13, 2018
34c2bd1
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 14, 2018
d0a266e
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 14, 2018
94fd88b
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 14, 2018
75df1c9
Print wrong dtype
TomAugspurger Dec 14, 2018
82c998a
Fix new failures
TomAugspurger Dec 14, 2018
9252c75
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 14, 2018
512af69
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 15, 2018
80b3455
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 16, 2018
87c125b
Update for comments
TomAugspurger Dec 16, 2018
b9f2d4e
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 17, 2018
a695eb8
minor cleanups
TomAugspurger Dec 17, 2018
bbc5f1b
Remove ref_to_data, deepcopy_if_needed
TomAugspurger Dec 17, 2018
a22f22c
Remove CategoricalIndex._index_data
TomAugspurger Dec 18, 2018
0aff5fa
Private _hasnans
TomAugspurger Dec 18, 2018
90a937f
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 18, 2018
1566c1e
really remove _deepcopy_if_needed
TomAugspurger Dec 18, 2018
cc80a8e
removed nbs
TomAugspurger Dec 18, 2018
58f3421
CLN: Removed unused wrap_array_method and accessor
TomAugspurger Dec 18, 2018
99bc78e
Remove unused setop handling
TomAugspurger Dec 18, 2018
ee48dc0
Notes on _index_data
TomAugspurger Dec 18, 2018
6e487c6
clarify comment
TomAugspurger Dec 18, 2018
f4aa1f8
Cleanups
TomAugspurger Dec 18, 2018
d81c204
Updates
TomAugspurger Dec 19, 2018
d821927
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 19, 2018
617a172
remove IncompatibleTimezoneError
TomAugspurger Dec 19, 2018
32ef700
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 19, 2018
0a0df77
add nonexistent
TomAugspurger Dec 19, 2018
169eae6
Fixed to_numpy on datetimetz
TomAugspurger Dec 19, 2018
be4335d
Try removing index _generate_ranges
TomAugspurger Dec 19, 2018
203a5a6
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 19, 2018
fab4c33
use _data
TomAugspurger Dec 19, 2018
89b5b51
Check before unboxing
TomAugspurger Dec 19, 2018
b2afd4e
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 20, 2018
a874f5f
na in unbox
TomAugspurger Dec 20, 2018
0eb28e8
Try removing freq infer
TomAugspurger Dec 20, 2018
42dfd30
bits of 24364
jbrockmendel Dec 20, 2018
f62544a
Merge pull request #6 from jbrockmendel/disown2
TomAugspurger Dec 21, 2018
2e30a56
Updates
TomAugspurger Dec 21, 2018
af815f8
Small updates
TomAugspurger Dec 21, 2018
b046791
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 21, 2018
4522dfe
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 21, 2018
eb594e7
Merge branch 'master' of https://github.com/pandas-dev/pandas into di…
jbrockmendel Dec 24, 2018
0b570b1
Merge pull request #7 from jbrockmendel/disown3
TomAugspurger Dec 27, 2018
72fe4fc
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 27, 2018
7a711f9
remove DatetimeTZBlock.shift
TomAugspurger Dec 27, 2018
6530500
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 27, 2018
445e46a
Merge branch 'master' of https://github.com/pandas-dev/pandas into di…
jbrockmendel Dec 28, 2018
9ae6706
Merge pull request #8 from jbrockmendel/disown5
TomAugspurger Dec 28, 2018
60ddcb5
Merge branch 'disown-tz-only-rebased' of https://github.com/TomAugspu…
TomAugspurger Dec 28, 2018
5988477
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 28, 2018
20c23b7
matching errors
TomAugspurger Dec 28, 2018
7a5fd94
isort
TomAugspurger Dec 28, 2018
e644d8c
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 28, 2018
4d3b55e
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 28, 2018
68cde94
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 28, 2018
421435a
Merge branch 'master' of https://github.com/pandas-dev/pandas into di…
jbrockmendel Dec 29, 2018
bbf7fa4
Merge pull request #9 from jbrockmendel/disown7
TomAugspurger Dec 29, 2018
324d452
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 29, 2018
cdec2a8
Removed pandas_registry and related tests
TomAugspurger Dec 29, 2018
e66c18b
Updates
TomAugspurger Dec 29, 2018
09c2c91
wrong branch
TomAugspurger Dec 29, 2018
6373948
Fix mixup from previous rebase
jbrockmendel Dec 29, 2018
e91bc09
Merge branch 'master' of https://github.com/pandas-dev/pandas into di…
jbrockmendel Dec 29, 2018
4bf00d8
Merge pull request #10 from jbrockmendel/disown8
TomAugspurger Dec 29, 2018
8cb7d9e
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 29, 2018
23fd9bb
fixup
TomAugspurger Dec 29, 2018
695010c
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 29, 2018
ec2c7af
move null-handling methods back down to null-handling section
jbrockmendel Dec 29, 2018
a499ed8
restore order of null-handling section
jbrockmendel Dec 29, 2018
a32e020
Small diff cleanups
jbrockmendel Dec 29, 2018
6d2fc99
Merge pull request #11 from jbrockmendel/na
TomAugspurger Dec 30, 2018
9342b59
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 30, 2018
c566ce8
Shift -> _data.time_shift
TomAugspurger Dec 30, 2018
f783770
Freq changes
TomAugspurger Dec 30, 2018
9502f90
Merge branch 'master' of https://github.com/pandas-dev/pandas into di…
jbrockmendel Dec 31, 2018
3e1ee5e
fix rebase scerwup
jbrockmendel Dec 31, 2018
92d8089
fix shift
jbrockmendel Dec 31, 2018
cbb90f7
fixups
jbrockmendel Dec 31, 2018
be1c968
Merge pull request #12 from jbrockmendel/disown10
TomAugspurger Dec 31, 2018
c655592
Merge branch 'disown-tz-only-rebased' of https://github.com/TomAugspu…
TomAugspurger Dec 31, 2018
8d2108a
eadata fixup
TomAugspurger Dec 31, 2018
fafa1ea
Fixed test overriting freq
TomAugspurger Dec 31, 2018
01f185b
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Dec 31, 2018
efa1c2c
remove unnecessary condition
TomAugspurger Dec 31, 2018
a65efb0
Update .array
TomAugspurger Dec 31, 2018
01115c4
Simplify diff
TomAugspurger Dec 31, 2018
9d37675
Revert eadata -> data changes
TomAugspurger Dec 31, 2018
38817a5
fix failing tests
jbrockmendel Jan 1, 2019
8fad32e
Merge pull request #13 from jbrockmendel/cifix
TomAugspurger Jan 1, 2019
5dbc63a
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Jan 1, 2019
7de78f1
Merge branch 'disown-tz-only-rebased' of https://github.com/TomAugspu…
TomAugspurger Jan 1, 2019
7544bcf
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Jan 1, 2019
39a2a67
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Jan 1, 2019
6e90823
import
TomAugspurger Jan 1, 2019
9e61b5b
Fixed failing test
TomAugspurger Jan 1, 2019
0be63a6
Try reverting dt64arr_to_periodarr
TomAugspurger Jan 1, 2019
90700fb
Minor fixups
TomAugspurger Jan 1, 2019
c77d49c
comment
TomAugspurger Jan 1, 2019
1499344
maybe unnecessary isinstance
TomAugspurger Jan 1, 2019
38a6eb6
Use class
TomAugspurger Jan 1, 2019
b7253d7
32-bit compat
TomAugspurger Jan 1, 2019
f11f07f
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Jan 1, 2019
ca11d27
Fixup merge
TomAugspurger Jan 1, 2019
4c2a620
use to_numpy
TomAugspurger Jan 1, 2019
adddef2
try returning dt64arr
TomAugspurger Jan 1, 2019
9498554
fixup! try returning dt64arr
TomAugspurger Jan 1, 2019
4f1c212
try simplifying categorical case
TomAugspurger Jan 1, 2019
40cdca8
abc
TomAugspurger Jan 1, 2019
756a4b6
Remove DatetimeIndexOpsMixin.__getitem__
TomAugspurger Jan 1, 2019
aea0e05
Remove DatetimeIndexOpsMixin.view
TomAugspurger Jan 1, 2019
dfa7fea
comment
TomAugspurger Jan 1, 2019
cc8b1ca
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Jan 1, 2019
6a2e1a1
Fixup merge
TomAugspurger Jan 1, 2019
b84bef1
Remove unused _time_shift
TomAugspurger Jan 1, 2019
69ed3d4
diff reduction
jbrockmendel Jan 2, 2019
4110b4c
Merge pull request #14 from jbrockmendel/reduction
TomAugspurger Jan 2, 2019
ce5f3b9
just index
TomAugspurger Jan 2, 2019
4c76ae1
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Jan 2, 2019
ef36be1
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Jan 2, 2019
ad4ea4d
fixup merge
TomAugspurger Jan 2, 2019
14a13b0
isort
TomAugspurger Jan 2, 2019
5c8d3c6
remove block
TomAugspurger Jan 2, 2019
2436214
Merge remote-tracking branch 'upstream/master' into disown-tz-only-re…
TomAugspurger Jan 2, 2019
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
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ Backwards incompatible API changes
- ``max_rows`` and ``max_cols`` parameters removed from :class:`HTMLFormatter` since truncation is handled by :class:`DataFrameFormatter` (:issue:`23818`)
- :func:`read_csv` will now raise a ``ValueError`` if a column with missing values is declared as having dtype ``bool`` (:issue:`20591`)
- The column order of the resultant :class:`DataFrame` from :meth:`MultiIndex.to_frame` is now guaranteed to match the :attr:`MultiIndex.names` order. (:issue:`22420`)
- Incorrectly passing a :class:`DatetimeIndex` to :meth:`MultiIndex.from_tuples`, rather than a sequence of tuples, now raises a ``TypeError`` rather than a ``ValueError`` (:issue:`24024`)
- :func:`pd.offsets.generate_range` argument ``time_rule`` has been removed; use ``offset`` instead (:issue:`24157`)

Percentage change on groupby
Expand Down Expand Up @@ -1368,6 +1369,7 @@ Datetimelike
- Bug in :class:`DataFrame` with ``datetime64[ns]`` dtype subtracting ``np.datetime64`` object with non-nanosecond unit failing to convert to nanoseconds (:issue:`18874`, :issue:`22163`)
- Bug in :class:`DataFrame` comparisons against ``Timestamp``-like objects failing to raise ``TypeError`` for inequality checks with mismatched types (:issue:`8932`, :issue:`22163`)
- Bug in :class:`DataFrame` with mixed dtypes including ``datetime64[ns]`` incorrectly raising ``TypeError`` on equality comparisons (:issue:`13128`, :issue:`22163`)
- Bug in :attr:`DataFrame.values` returning a :class:`DatetimeIndex` for a single-column ``DataFrame`` with tz-aware datetime values. Now a 2-D :class:`numpy.ndarray` of :class:`Timestamp` objects is returned (:issue:`24024`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make to .to_numpy()

- Bug in :meth:`DataFrame.eq` comparison against ``NaT`` incorrectly returning ``True`` or ``NaN`` (:issue:`15697`, :issue:`22163`)
- Bug in :class:`DatetimeIndex` subtraction that incorrectly failed to raise ``OverflowError`` (:issue:`22492`, :issue:`22508`)
- Bug in :class:`DatetimeIndex` incorrectly allowing indexing with ``Timedelta`` object (:issue:`20464`)
Expand All @@ -1384,6 +1386,7 @@ Datetimelike
- Bug in :func:`period_range` ignoring the frequency of ``start`` and ``end`` when those are provided as :class:`Period` objects (:issue:`20535`).
- 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:`DataFrame` when creating a new column from an ndarray of :class:`Timestamp` objects with timezones creating an object-dtype column, rather than datetime with timezone (:issue:`23932`)
- 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`)
Expand Down
9 changes: 7 additions & 2 deletions pandas/_libs/src/ujson/python/objToJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ static PyObject *get_values(PyObject *obj) {
PRINTMARK();

TomAugspurger marked this conversation as resolved.
Show resolved Hide resolved
if (values && !PyArray_CheckExact(values)) {

if (PyObject_HasAttrString(values, "to_numpy")) {
TomAugspurger marked this conversation as resolved.
Show resolved Hide resolved
values = PyObject_CallMethod(values, "to_numpy", NULL);
}

if (PyObject_HasAttrString(values, "values")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove this branch for .values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's possible to get Block here, which doesn't currently have a to_numpy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, ok can you add a TODO / maybe an issue (we need one about serialization anyhow)

PyObject *subvals = get_values(values);
PyErr_Clear();
Expand Down Expand Up @@ -279,8 +284,8 @@ static PyObject *get_values(PyObject *obj) {
repr = PyString_FromString("<unknown dtype>");
}

PyErr_Format(PyExc_ValueError, "%s or %s are not JSON serializable yet",
PyString_AS_STRING(repr), PyString_AS_STRING(typeRepr));
PyErr_Format(PyExc_ValueError, "%R or %R are not JSON serializable yet",
repr, typeRepr);
Py_DECREF(repr);
Py_DECREF(typeRepr);

Expand Down
7 changes: 4 additions & 3 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def cmp_method(self, other):
if isinstance(other, ABCDataFrame):
return NotImplemented

if isinstance(other, (np.ndarray, ABCIndexClass, ABCSeries)):
if isinstance(other, (np.ndarray, ABCIndexClass, ABCSeries, cls)):
jbrockmendel marked this conversation as resolved.
Show resolved Hide resolved
if other.ndim > 0 and len(self) != len(other):
raise ValueError('Lengths must match to compare')

Expand Down Expand Up @@ -1162,9 +1162,10 @@ def _addsub_offset_array(self, other, op):
left = lib.values_from_object(self.astype('O'))

res_values = op(left, np.array(other))
kwargs = {}
if not is_period_dtype(self):
return type(self)(res_values, freq='infer')
return self._from_sequence(res_values)
kwargs['freq'] = 'infer'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't it be better to have this the default in PeriodArray._from_sequence? (e.g. freq='infer')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is strange, since freq isn't a keyword for PeriodArray._from_sequence.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so how can this be working now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I missed the not. DatetimeArray._from_sequence and TimedeltaArray._from_sequence both take a freq.

For PeriodArray, freq is embedded in the dtype.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use the original format, seems way more clear here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't, since frequency inference isn't (currently) allowed in DatetimeArray.__init__ (writing up an issue about that now).

return self._from_sequence(res_values, **kwargs)

def _time_shift(self, periods, freq=None):
"""
Expand Down
147 changes: 111 additions & 36 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ def _dt_array_cmp(cls, op):

def wrapper(self, other):
meth = getattr(dtl.DatetimeLikeArrayMixin, opname)
# TODO: return NotImplemented for Series / Index and let pandas unbox
# Right now, returning NotImplemented for Index fails because we
# go into the index implementation, which may be a bug?
jbrockmendel marked this conversation as resolved.
Show resolved Hide resolved

other = lib.item_from_zerodim(other)

Expand Down Expand Up @@ -145,9 +148,16 @@ def wrapper(self, other):
return ops.invalid_comparison(self, other, op)
else:
self._assert_tzawareness_compat(other)
if not hasattr(other, 'asi8'):
# ndarray, Series
other = type(self)(other)
if isinstance(other, (ABCIndexClass, ABCSeries)):
other = other.array
jreback marked this conversation as resolved.
Show resolved Hide resolved

if (is_datetime64_dtype(other) and
not is_datetime64_ns_dtype(other) or
not hasattr(other, 'asi8')):
TomAugspurger marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a layer of parens to disambiguate the and/or

# e.g. other.dtype == 'datetime64[s]'
# or an object-dtype ndarray
other = type(self)._from_sequence(other)

result = meth(self, other)
o_mask = other._isnan

Expand All @@ -171,10 +181,24 @@ class DatetimeArrayMixin(dtl.DatetimeLikeArrayMixin,
dtl.TimelikeOps,
TomAugspurger marked this conversation as resolved.
Show resolved Hide resolved
dtl.DatelikeOps):
"""
Assumes that subclass __new__/__init__ defines:
tz
_freq
_data
Pandas ExtensionArray for tz-naive or tz-aware datetime data.

.. versionadded:: 0.24.0

Parameters
----------
values : Series, Index, DatetimeArray, ndarray
The datetime data.

For DatetimeArray `values` (or a Series or Index boxing one),
`dtype` and `freq` will be extracted from `values`, with
precedence given to

dtype : numpy.dtype or DatetimeTZDtype
Note that the only NumPy dtype allowed is 'datetime64[ns]'.
freq : str or Offset, optional
copy : bool, default False
Whether to copy the underlying array of values.
"""
_typ = "datetimearray"
_scalar_type = Timestamp
Expand Down Expand Up @@ -213,38 +237,84 @@ class DatetimeArrayMixin(dtl.DatetimeLikeArrayMixin,
_dtype = None # type: Union[np.dtype, DatetimeTZDtype]
_freq = None

@classmethod
def _simple_new(cls, values, freq=None, tz=None):
"""
we require the we have a dtype compat for the values
if we are passed a non-dtype compat, then coerce using the constructor
"""
assert isinstance(values, np.ndarray), type(values)
def __init__(self, values, dtype=_NS_DTYPE, freq=None, copy=False):
TomAugspurger marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(values, (ABCSeries, ABCIndexClass)):
values = values._values

if isinstance(values, type(self)):
# validation
dtz = getattr(dtype, 'tz', None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can none of the helper functions at the bottom of the module be used to de-duplicate some of this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which ones do you have in mind?

I think the tz / dtype validation is different. Those (e.g. validate_tz_from_dtype) seem to be concerned with validating a user-provided tz against a DatetimeTZDtype. We're concerned with an instances of a DatetimeArray and a dtype which may be a NumPy dtype or a DatetimeTZDtype.

if dtz and values.tz is None:
dtype = DatetimeTZDtype(tz=dtype.tz)
elif dtz and values.tz:
if not timezones.tz_compare(dtz, values.tz):
msg = (
"Timezone of the array and 'dtype' do not match. "
"'{}' != '{}'"
)
raise TypeError(msg.format(dtz, values.tz))
elif values.tz:
dtype = values.dtype
# freq = validate_values_freq(values, freq)
if freq is None:
freq = values.freq
values = values._data

if not isinstance(values, np.ndarray):
msg = (
"Unexpected type '{}'. 'values' must be a DatetimeArray "
"ndarray, or Series or Index containing one of those."
)
raise ValueError(msg.format(type(values).__name__))
TomAugspurger marked this conversation as resolved.
Show resolved Hide resolved

if values.dtype == 'i8':
jreback marked this conversation as resolved.
Show resolved Hide resolved
# for compat with datetime/timedelta/period shared methods,
# we can sometimes get here with int64 values. These represent
# nanosecond UTC (or tz-naive) unix timestamps
values = values.view(_NS_DTYPE)

assert values.dtype == 'M8[ns]', values.dtype
if values.dtype != _NS_DTYPE:
TomAugspurger marked this conversation as resolved.
Show resolved Hide resolved
msg = (
"The dtype of 'values' is incorrect. Must be 'datetime64[ns]'."
" Got {} instead."
)
raise ValueError(msg.format(values.dtype))
TomAugspurger marked this conversation as resolved.
Show resolved Hide resolved

result = object.__new__(cls)
result._data = values
result._freq = freq
if tz is None:
dtype = _NS_DTYPE
else:
tz = timezones.maybe_get_tz(tz)
tz = timezones.tz_standardize(tz)
dtype = DatetimeTZDtype('ns', tz)
result._dtype = dtype
return result
dtype = pandas_dtype(dtype)
_validate_dt64_dtype(dtype)
jreback marked this conversation as resolved.
Show resolved Hide resolved

def __new__(cls, values, freq=None, tz=None, dtype=None, copy=False,
dayfirst=False, yearfirst=False, ambiguous='raise'):
return cls._from_sequence(
values, freq=freq, tz=tz, dtype=dtype, copy=copy,
dayfirst=dayfirst, yearfirst=yearfirst, ambiguous=ambiguous)
if freq == "infer":
msg = (
"Frequency inference not allowed in DatetimeArray.__init__. "
"Use 'pd.array()' instead."
)
raise ValueError(msg)

if copy:
values = values.copy()
if freq:
freq = to_offset(freq)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto re not doing freq validation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you have a longer comment on this somewhere? I seem to have lost it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/pandas-dev/pandas/pull/24024/files#r243105181

There is a request-for-fleshing-out there that I'll get to now.

if getattr(dtype, 'tz', None):
# https://github.com/pandas-dev/pandas/issues/18595
# Ensure that we have a standard timezone for pytz objects.
# Without this, things like adding an array of timedeltas and
# a tz-aware Timestamp (with a tz specific to its datetime) will
# be incorrect(ish?) for the array as a whole
dtype = DatetimeTZDtype(tz=timezones.tz_standardize(dtype.tz))
jreback marked this conversation as resolved.
Show resolved Hide resolved

self._data = values
self._dtype = dtype
self._freq = freq
jreback marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def _simple_new(cls, values, freq=None, tz=None):
TomAugspurger marked this conversation as resolved.
Show resolved Hide resolved
"""
we require the we have a dtype compat for the values
if we are passed a non-dtype compat, then coerce using the constructor
"""
dtype = DatetimeTZDtype(tz=tz) if tz else _NS_DTYPE

return cls(values, freq=freq, dtype=dtype)

@classmethod
def _from_sequence(cls, data, dtype=None, copy=False,
Expand Down Expand Up @@ -459,8 +529,7 @@ def __array__(self, dtype=None):
elif is_int64_dtype(dtype):
return self.asi8

# TODO: warn that conversion may be lossy?
return self._data.view(np.ndarray) # follow Index.__array__
return self._data
jreback marked this conversation as resolved.
Show resolved Hide resolved

def __iter__(self):
"""
Expand Down Expand Up @@ -519,7 +588,7 @@ def astype(self, dtype, copy=True):

@Appender(dtl.DatetimeLikeArrayMixin._validate_fill_value.__doc__)
def _validate_fill_value(self, fill_value):
if isna(fill_value):
if isna(fill_value) or fill_value == iNaT:
jbrockmendel marked this conversation as resolved.
Show resolved Hide resolved
fill_value = iNaT
elif isinstance(fill_value, (datetime, np.datetime64)):
self._assert_tzawareness_compat(fill_value)
Expand Down Expand Up @@ -1574,6 +1643,9 @@ def sequence_to_dt64ns(data, dtype=None, copy=False,
# if dtype has an embedded tz, capture it
tz = validate_tz_from_dtype(dtype, tz)

if isinstance(data, ABCIndexClass):
data = data._data
TomAugspurger marked this conversation as resolved.
Show resolved Hide resolved

# By this point we are assured to have either a numpy array or Index
data, copy = maybe_convert_dtype(data, copy)

Expand All @@ -1590,12 +1662,15 @@ def sequence_to_dt64ns(data, dtype=None, copy=False,
data, dayfirst=dayfirst, yearfirst=yearfirst)
tz = maybe_infer_tz(tz, inferred_tz)

# `data` may have originally been a Categorical[datetime64[ns, tz]],
# so we need to handle these types.
if is_datetime64tz_dtype(data):
# DatetimeArray -> ndarray
tz = maybe_infer_tz(tz, data.tz)
result = data._data

elif is_datetime64_dtype(data):
# tz-naive DatetimeArray/Index or ndarray[datetime64]
# tz-naive DatetimeArray or ndarray[datetime64]
data = getattr(data, "_data", data)
if data.dtype != _NS_DTYPE:
data = conversion.ensure_datetime64ns(data)
Expand Down Expand Up @@ -1750,7 +1825,7 @@ def maybe_convert_dtype(data, copy):
# GH#18664 preserve tz in going DTI->Categorical->DTI
# TODO: cases where we need to do another pass through this func,
# e.g. the categories are timedelta64s
data = data.categories.take(data.codes, fill_value=NaT)
data = data.categories.take(data.codes, fill_value=NaT)._values
jbrockmendel marked this conversation as resolved.
Show resolved Hide resolved
copy = False

elif is_extension_type(data) and not is_datetime64tz_dtype(data):
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ def __init__(self, values, freq=None, dtype=None, copy=False):

@classmethod
def _simple_new(cls, values, freq=None, **kwargs):
# TODO(DatetimeArray): remove once all constructors are aligned.
# alias from PeriodArray.__init__
# alias for PeriodArray.__init__
return cls(values, freq=freq, **kwargs)

@classmethod
Expand Down
Loading