Compare skewness and kurtosis across pandas and SciPy bias conventions
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Other
Implement `shape_convention_audit(s: pd.Series) -> pd.Series`, which returns the skewness and kurtosis of `s` under each bias convention side by side. Let `a = s.to_numpy()`.
The returned Series holds these six values:
- `pandas_skew` is `s.skew()` and `pandas_kurt` is `s.kurt()`.
- `scipy_skew_biased` is `scipy.stats.skew(a)` and `scipy_skew_unbiased` is `scipy.stats.skew(a, bias=False)`.
- `scipy_kurt_biased` is `scipy.stats.kurtosis(a, fisher=True)` and `scipy_kurt_unbiased` is `scipy.stats.kurtosis(a, fisher=True, bias=False)`.
The index order must be exactly `['pandas_skew', 'scipy_skew_biased', 'scipy_skew_unbiased', 'pandas_kurt', 'scipy_kurt_biased', 'scipy_kurt_unbiased']`. The dtype is `float64` and `.name` is `None`. Return the Series; do not print it.
```hint Library defaults
Check the default value of `bias` in `scipy.stats.skew` and `scipy.stats.kurtosis`, and look up whether `Series.kurt()` reports excess kurtosis or raw kurtosis.
```
```hint Building the output
Build the values from one explicit list of keys so the index order cannot drift, and check what dtype and `.name` a freshly constructed Series gets.
```
### Constraints & Assumptions
- The test input is a fixed Series of 15 floats with no `NaN`.
- The result is compared with `pandas.testing.assert_series_equal`, so index order, dtype and name all have to match.
- On that input, `np.isclose(out['pandas_skew'], out['scipy_skew_unbiased'])` and `np.isclose(out['pandas_kurt'], out['scipy_kurt_unbiased'])` are both true, while the `*_biased` entries differ.
### What a Strong Answer Covers
- All six statistics computed with the stated arguments on one shared NumPy array.
- A `float64` Series in the exact index order, with no name, returned instead of printed.
- Which default convention each library uses for skewness and kurtosis, and why pandas lines up with one particular SciPy setting.
- How the correction factors depend on the sample size.
- Inputs that break the two invariants, such as missing values, very short Series and constant values.
### Follow-up Questions
- Why do the biased and unbiased estimators diverge more for small `n`?
- How would you handle `NaN` values in the input Series?
- What happens to the two invariants for a Series with fewer than four values, or with every value equal?
Overview: Write a pandas function that reports skewness and kurtosis under the pandas defaults and under SciPy's biased and bias-corrected settings, returned as a fixed-order Series. It tests how sample moment corrections, excess kurtosis and library defaults differ, and which inputs make them disagree.