(self, values, fill_value=None)
| 277 | return result |
| 278 | |
| 279 | def get_new_values(self, values, fill_value=None): |
| 280 | if values.ndim == 1: |
| 281 | values = values[:, np.newaxis] |
| 282 | |
| 283 | sorted_values = self._make_sorted_values(values) |
| 284 | |
| 285 | # place the values |
| 286 | length, width = self.full_shape |
| 287 | stride = values.shape[1] |
| 288 | result_width = width * stride |
| 289 | result_shape = (length, result_width) |
| 290 | mask = self.mask |
| 291 | mask_all = self.mask_all |
| 292 | |
| 293 | # we can simply reshape if we don't have a mask |
| 294 | if mask_all and len(values): |
| 295 | # TODO: Under what circumstances can we rely on sorted_values |
| 296 | # matching values? When that holds, we can slice instead |
| 297 | # of take (in particular for EAs) |
| 298 | new_values = ( |
| 299 | sorted_values.reshape(length, width, stride) |
| 300 | .swapaxes(1, 2) |
| 301 | .reshape(result_shape) |
| 302 | ) |
| 303 | new_mask = np.ones(result_shape, dtype=bool) |
| 304 | return new_values, new_mask |
| 305 | |
| 306 | dtype = values.dtype |
| 307 | |
| 308 | if isinstance(dtype, ExtensionDtype): |
| 309 | # GH#41875 |
| 310 | # We are assuming that fill_value can be held by this dtype, |
| 311 | # unlike the non-EA case that promotes. |
| 312 | cls = dtype.construct_array_type() |
| 313 | new_values = cls._empty(result_shape, dtype=dtype) |
| 314 | if not mask_all: |
| 315 | new_values[:] = fill_value |
| 316 | else: |
| 317 | if not mask_all: |
| 318 | old_dtype = dtype |
| 319 | dtype, fill_value = maybe_promote(dtype, fill_value) |
| 320 | if old_dtype != dtype: |
| 321 | if old_dtype.kind not in "iub": |
| 322 | warnings.warn( |
| 323 | # GH#12189, GH#53868 |
| 324 | "Using a fill_value that cannot be held in the existing " |
| 325 | "dtype is deprecated and will raise in a future version.", |
| 326 | Pandas4Warning, |
| 327 | stacklevel=find_stack_level(), |
| 328 | ) |
| 329 | elif not isna(fill_value): |
| 330 | warnings.warn( |
| 331 | # GH#12189, GH#53868 |
| 332 | "Using a fill_value that cannot be held in the existing " |
| 333 | "dtype is deprecated and will raise in a future version.", |
| 334 | Pandas4Warning, |
| 335 | stacklevel=find_stack_level(), |
| 336 | ) |
no test coverage detected