Skip to content

BUG: scalar indexing on 2D DTA/TDA/PA #33342

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 28 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
03d07df
BUG: 2D indexing on DTA/TDA/PA
jbrockmendel Apr 4, 2020
8cf6c3b
BUG: Fix segfault in GroupBy.count and DataFrame.count (#32842)
tv3141 Apr 4, 2020
7072981
TYP: require Index objects earlier in internals (#33100)
jbrockmendel Apr 4, 2020
9526c32
DOC: Fixed examples in `pandas/core/accessor.py` (#33260)
ShaharNaveh Apr 4, 2020
87c4704
Troubleshoot Travis (#33280)
jbrockmendel Apr 4, 2020
de53657
TST: add DataFrame test for construct from tuple case from GH-32776 (…
BenjaminLiuPenrose Apr 4, 2020
c1f2906
DOC: Fixed examples in `pandas/core/window` (#33266)
ShaharNaveh Apr 4, 2020
f98db69
DOC: Fix error in Series.clip and DataFrame.clip (#33282)
farhanreynaldo Apr 4, 2020
1de584d
TYP: Fixed type annotaions in `scripts/validate_rst_title_capitalizat…
ShaharNaveh Apr 4, 2020
d507fe6
TYP: pandas/core/dtypes/dtypes.py (#31384)
simonjayhawkins Apr 5, 2020
b7c9824
TST: add date range test for reindex case from GH-32740 (#33265)
BenjaminLiuPenrose Apr 5, 2020
adba667
REF: BlockManager.combine -> _combine (#33294)
jbrockmendel Apr 5, 2020
5550f27
REF: make kwargs explicit in BlockManager methods (#33295)
jbrockmendel Apr 5, 2020
7113911
DOC/CLN: remove versionadded/changed:: 0.21 (#33301)
simonjayhawkins Apr 5, 2020
9c74fc9
CLN: Add/refine type hints to some functions in core.dtypes.cast (#33…
rhshadrach Apr 5, 2020
d1cc4e7
DEPR: Index.is_mixed (#33291)
jbrockmendel Apr 5, 2020
57a6537
CLN: Added static types _libs/algos (#33271)
ShaharNaveh Apr 5, 2020
55171c2
CLN: remove BlockManager.__contains__ (#33293)
jbrockmendel Apr 5, 2020
eb080f3
DOC: Improved doc for `Index.equals` (#33289)
ShaharNaveh Apr 6, 2020
2f5af5e
DOC/CLN: Fix docstring typo (#33320)
dsaxton Apr 6, 2020
dfa6f44
DOC: include Offset.__call__ to autosummary to fix sphinx warning (#3…
jbrockmendel Apr 6, 2020
c52f831
BUG: DataFrame._item_cache not cleared on on .copy() (#33299)
neilkg Apr 6, 2020
563a64e
CLN: Added static types for `pandas/_libs/reduction.pyx` (#33316)
ShaharNaveh Apr 6, 2020
b44021d
Changed files permissions to be the same (#33318)
ShaharNaveh Apr 6, 2020
927b695
PERF: fix placement when slicing a Series (#33324)
jorisvandenbossche Apr 6, 2020
2f3cd7d
BUG: scalar lookup on 2D DTA/TDA/PA
jbrockmendel Apr 6, 2020
8a1700e
Merge branch 'master' of https://github.com/pandas-dev/pandas into bl…
jbrockmendel Apr 6, 2020
04d9f63
Merge branch 'master' of https://github.com/pandas-dev/pandas into bl…
jbrockmendel Apr 6, 2020
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: 2 additions & 0 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ def __getitem__(self, key):
freq = self.freq

result = getitem(key)
if lib.is_scalar(result):
return self._box_func(result)
return self._simple_new(result, dtype=self.dtype, freq=freq)

def __setitem__(
Expand Down
9 changes: 2 additions & 7 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np

from pandas._libs import NaT, Timestamp, algos as libalgos, lib, writers
from pandas._libs import NaT, algos as libalgos, lib, writers
import pandas._libs.internals as libinternals
from pandas._libs.tslibs import Timedelta, conversion
from pandas._libs.tslibs.timezones import tz_compare
Expand Down Expand Up @@ -2023,12 +2023,7 @@ def array_values(self):
def iget(self, key):
# GH#31649 we need to wrap scalars in Timestamp/Timedelta
# TODO(EA2D): this can be removed if we ever have 2D EA
result = super().iget(key)
if isinstance(result, np.datetime64):
result = Timestamp(result)
elif isinstance(result, np.timedelta64):
result = Timedelta(result)
return result
return self.array_values().reshape(self.shape)[key]

def shift(self, periods, axis=0, fill_value=None):
# TODO(EA2D) this is unnecessary if these blocks are backed by 2D EAs
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/arrays/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ def test_getitem_2d(self, arr1d):
result = arr2d[:3, 0]
tm.assert_equal(result, expected)

# Scalar lookup
result = arr2d[-1, 0]
expected = arr1d[-1]
assert result == expected

def test_setitem(self):
data = np.arange(10, dtype="i8") * 24 * 3600 * 10 ** 9
arr = self.array_cls(data, freq="D")
Expand Down