MCPcopy
hub / github.com/pandas-dev/pandas / ensure_block_shape

Function ensure_block_shape

pandas/core/internals/blocks.py:2354–2367  ·  view source on GitHub ↗

Reshape if possible to have values.ndim == ndim.

(values: ArrayLike, ndim: int = 1)

Source from the content-addressed store, hash-verified

2352
2353
2354def ensure_block_shape(values: ArrayLike, ndim: int = 1) -> ArrayLike:
2355 """
2356 Reshape if possible to have values.ndim == ndim.
2357 """
2358
2359 if values.ndim < ndim:
2360 if not is_1d_only_ea_dtype(values.dtype):
2361 # TODO(EA2D): https://github.com/pandas-dev/pandas/issues/23023
2362 # block.shape is incorrect for "2D" ExtensionArrays
2363 # We can't, and don't need to, reshape.
2364 values = cast("np.ndarray | DatetimeArray | TimedeltaArray", values)
2365 values = values.reshape(1, -1)
2366
2367 return values
2368
2369
2370def external_values(values: ArrayLike) -> ArrayLike:

Callers 15

_make_blockFunction · 0.90
make_blockFunction · 0.90
ndarray_to_mgrFunction · 0.90
isetMethod · 0.90
insertMethod · 0.90
to_2d_mgrMethod · 0.90
_form_blocksFunction · 0.90
concatenate_managersFunction · 0.90
_concatenate_join_unitsFunction · 0.90
_agg_py_fallbackMethod · 0.90
create_blockFunction · 0.90

Calls 2

is_1d_only_ea_dtypeFunction · 0.90
reshapeMethod · 0.45

Tested by 1

create_blockFunction · 0.72