Skip to content

CLN: Standardize values coercion during Block initialization  #19492

Closed
@TomAugspurger

Description

@TomAugspurger

Splitting off from #19268 (which is starting to give me unicorns fairly often)

After that, all blocks eventually end up calling Block.__init__ (aside from ScalarBlock, which we'll ignore).

Most of the subclasses init methods are

  1. maybe coerce values to the expected dtype
  2. call super().__init__

It'd be nice to put 1 into favor of a _maybe_coerce_values method defined by each block, and remove all the subclasses init methods.

The one sticking point will be DatetimeTZBlock.__init__, which accepts a dtype parameter that no other block does.

def __init__(self, values, placement, ndim=2, dtype=None):
if not isinstance(values, self._holder):
values = self._holder(values)
if dtype is not None:
if isinstance(dtype, compat.string_types):
dtype = DatetimeTZDtype.construct_from_string(dtype)
values = values._shallow_copy(tz=dtype.tz)

We could maybe push that onto the callers, and then clean things up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CleanInternalsRelated to non-user accessible pandas implementationRefactorInternal refactoring of code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions