Skip to content

Commit

Permalink
WIP commit before merge
Browse files Browse the repository at this point in the history
Underlying numba chnages has broken my local testing.  Preparing to resync with main branch to resolve.

Signed-off-by: Michael Tiemann <[email protected]>
  • Loading branch information
MichaelTiemannOSC committed Aug 24, 2023
1 parent 0c64095 commit 7e7cecc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
7 changes: 5 additions & 2 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,17 @@ def _from_sequence(cls, scalars, *, dtype: Dtype | None = None, copy: bool = Fal
raise AbstractMethodError(cls)

@classmethod
def _from_scalars(cls, scalars, *, dtype: DtypeObj) -> Self:
def _from_scalars(cls, scalars, *, dtype: DtypeObj | None = None) -> Self:
"""
Strict analogue to _from_sequence, allowing only sequences of scalars
that should be specifically inferred to the given dtype.
Parameters
----------
scalars : sequence
dtype : ExtensionDtype
dtype : ExtensionDtype, optional
This could be a Dtype competible with the ExtensionArray,
but it is up to _from_scalars to choose (from scalars,
dtype, or however) the ultimate dtype for the return value.
Raises
------
TypeError or ValueError
Expand Down
26 changes: 9 additions & 17 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,30 +971,22 @@ def fast_xs(self, loc: int) -> SingleBlockManager:

if isinstance(dtype, ExtensionDtype) and not immutable_ea:
cls = dtype.construct_array_type()
else:
cls = None

if hasattr(cls, "_from_scalars"):
obj = self.blocks[0].iget((slice(None), loc))
result = cls._from_scalars(
[
blk.iget((i, loc))
for blk in self.blocks
for i, rl in enumerate(blk.mgr_locs)
for i, _ in enumerate(blk.mgr_locs)
],
dtype=obj.dtype,
dtype=dtype,
)
else:
if cls is not None:
result = cls._empty((n,), dtype=dtype)
else:
# error: Argument "dtype" to "empty" has incompatible type
# "Union[Type[object], dtype[Any], ExtensionDtype, None]"; expected
# "None"
result = np.empty(
n, dtype=object if immutable_ea else dtype # type: ignore[arg-type]
)
result = ensure_wrapped_if_datetimelike(result)
# error: Argument "dtype" to "empty" has incompatible type
# "Union[Type[object], dtype[Any], ExtensionDtype, None]"; expected
# "None"
result = np.empty(
n, dtype=object if immutable_ea else dtype # type: ignore[arg-type]
)
result = ensure_wrapped_if_datetimelike(result)

for blk in self.blocks:
# Such assignment may incorrectly coerce NaT to None
Expand Down

0 comments on commit 7e7cecc

Please sign in to comment.