(s, idx=None)
| 453 | |
| 454 | @meta_nonempty.register(pd.Series) |
| 455 | def _nonempty_series(s, idx=None): |
| 456 | # TODO: Use register dtypes with make_array_nonempty |
| 457 | if idx is None: |
| 458 | idx = _nonempty_index(s.index) |
| 459 | dtype = s.dtype |
| 460 | if len(s) > 0: |
| 461 | # use value from meta if provided |
| 462 | data = [s.iloc[0]] * 2 |
| 463 | elif isinstance(dtype, pd.DatetimeTZDtype): |
| 464 | entry = pd.Timestamp("1970-01-01", tz=dtype.tz) |
| 465 | data = pd.array([entry, entry], dtype=dtype) |
| 466 | elif isinstance(dtype, pd.CategoricalDtype): |
| 467 | if len(s.cat.categories): |
| 468 | codes = [0, 0] |
| 469 | else: |
| 470 | codes = [-1, -1] |
| 471 | data = pd.Categorical.from_codes(codes, dtype=s.dtype) |
| 472 | elif is_integer_na_dtype(dtype): |
| 473 | data = pd.array([1, None], dtype=dtype) |
| 474 | elif is_float_na_dtype(dtype): |
| 475 | data = pd.array([1.0, None], dtype=dtype) |
| 476 | elif isinstance(dtype, pd.PeriodDtype): |
| 477 | # pandas 0.24.0+ should infer this to be Series[Period[freq]] |
| 478 | freq = dtype.freq |
| 479 | data = [pd.Period("2000", freq), pd.Period("2001", freq)] |
| 480 | elif isinstance(dtype, pd.SparseDtype): |
| 481 | entry = _scalar_from_dtype(dtype.subtype) |
| 482 | data = pd.array([entry, entry], dtype=dtype) |
| 483 | elif isinstance(dtype, pd.IntervalDtype): |
| 484 | entry = _scalar_from_dtype(dtype.subtype) |
| 485 | data = pd.array([entry, entry], dtype=dtype) |
| 486 | elif type(dtype) in make_array_nonempty._lookup: |
| 487 | data = make_array_nonempty(dtype) |
| 488 | else: |
| 489 | entry = _scalar_from_dtype(dtype) |
| 490 | data = np.array([entry, entry], dtype=dtype) |
| 491 | |
| 492 | out = pd.Series(data, name=s.name, index=idx) |
| 493 | out.attrs = s.attrs |
| 494 | return out |
| 495 | |
| 496 | |
| 497 | @meta_lib_from_array.register(Array) |
no test coverage detected