def to_array(self, dtype: DtypeObj) -> ArrayLike: """ Helper function to create the actual all-NA array from the NullArrayProxy object. Parameters ---------- arr : NullArrayProxy dtype : the dtype for the resulting array Returns ------- np.ndarray or ExtensionArray """ if isinstance(dtype, ExtensionDtype): empty = dtype.construct_array_type()._from_sequence([], dtype=dtype) indexer = -np.ones(self.n, dtype=np.intp) return empty.take(indexer, allow_fill=True) else: # when introducing missing values, int becomes float, bool becomes object dtype = ensure_dtype_can_hold_na(dtype) fill_value = na_value_for_dtype(dtype) arr = np.empty(self.n, dtype=dtype) arr.fill(fill_value) return ensure_wrapped_if_datetimelike(arr)
def _get_empty_dtype(join_units: Sequence[JoinUnit]) -> DtypeObj: """ Return dtype and N/A values to use when concatenating specified units. Returned N/A value may be None which means there was no casting involved. Returns ------- dtype """ if len(join_units) == 1: blk = join_units[0].block if blk is None: return np.dtype(np.float64) if _is_uniform_reindex(join_units): # FIXME: integrate property empty_dtype = join_units[0].block.dtype return empty_dtype has_none_blocks = any(unit.block is None for unit in join_units) dtypes = [ unit.dtype for unit in join_units if unit.block is not None and not unit.is_na ] if not len(dtypes): dtypes = [unit.dtype for unit in join_units if unit.block is not None] dtype = find_common_type(dtypes) if has_none_blocks: dtype = ensure_dtype_can_hold_na(dtype) return dtype
def _get_empty_dtype(join_units: Sequence[JoinUnit]) -> DtypeObj: """ Return dtype and N/A values to use when concatenating specified units. Returned N/A value may be None which means there was no casting involved. Returns ------- dtype """ if len(join_units) == 1: blk = join_units[0].block return blk.dtype if _is_uniform_reindex(join_units): empty_dtype = join_units[0].block.dtype return empty_dtype needs_can_hold_na = any(unit.is_na for unit in join_units) dtypes = [unit.block.dtype for unit in join_units if not unit.is_na] dtype = find_common_type(dtypes) if needs_can_hold_na: dtype = ensure_dtype_can_hold_na(dtype) return dtype
def dtype(self): blk = self.block if blk is None: raise AssertionError("Block is None, no dtype") if not self.needs_filling: return blk.dtype return ensure_dtype_can_hold_na(blk.dtype)
def dtype(self) -> DtypeObj: blk = self.block if blk.values.dtype.kind == "V": raise AssertionError("Block is None, no dtype") if not self.needs_filling: return blk.dtype return ensure_dtype_can_hold_na(blk.dtype)