BUG: quantile segfaults on invalid quantile values
- [x] closes #27470
- [ ] waiting for #27584 to be resolved (move `check_percentiles` out of `NDFrame`)
- [ ] waiting for #27526 to be resolved (#20405 cythonized `Groupby.quantile` with functionality regression)
- [ ] whatsnew entry

fixes this here makes sense.  is the underlying problem in numpy or in one of our cython functions? >  is the underlying problem in numpy or in one of our cython functions?

I think this line is the problem
https://github.com/pydata/pandas/blob/d48306e77c0a708e0ee33a2aa1da7e267df52ef6/pandas/_libs/groupby.pyx#L758-L759

it calculates an index by using the quantile value as a fraction of array length.
 > if we were to move that to PandasObject to share across NDFrame and GroupBy would that be even 
> simpler?

Yeah, `_check_percentile` is what this does. I don't think it fits in `PandasObject`, maybe in lib.pyx instead? it lives on NDFrame but is actually a standalone static method. Let's put the check in the cython function, so as to preclude any chance of the segfault showing up, e.g. if we call it from somewhere else Logical, but thorny. Is the overall approach in pandas to put input validation in cython in the python  caller? could also usea python wrapper which is the only cython caller.

@WillAyd  suggests reusing `NDFrame._check_percentiles` instead. It's often inconsistent standards about where validation should happen that creates these sort of bugs, so maybe a bigger issue here.

Whatever there's agreement on is fine by me. > but thorny

what is thorny about it?  I haven't looked at this too specifically, just in principle would rather segfault-prevention happen as close to the fault as possible blocked by #27526 waiting for #27584 This was a simple fix, but it now depends on too many other small things. I'm sure someone else will get it eventually.