ENH: pd.series.sample when n > len #57584
Labels
Closing Candidate
May be closeable, needs more eyeballs
Enhancement
Error Reporting
Incorrect or improved errors from pandas
Series
Series data structure
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
Oftentimes, I have some code that samples from a df / series, as in
and given new data,
sample_size > len(df)
, gettingI'd like a way to specify that if
sample_size > len(df)
, I just want all elements back. This is already the case with.head()
. So I don't really understand why the behaviour is not the same here.Feature Description
I can see two possible solutions
As in here, "If n is larger than the number of rows, this function returns all rows."
If keping back-compatibility is a must, then adding a parameter
errors
, with possible valuesignore
orraise
(default beingraise
, again to keep back-compatibility).I'd lean towards (1), but I'd be content with (2)
Alternative Solutions
I proposed two solutions. Of course, one can always add a line
before the call, but I honestly think pandas should provide support for this common case + being consistent with other methods e.g.
head
.Additional Context
Happy to contribute with this feature, but first checking here. Just making sure owners would consider it, and nobody is working on this atm.
The text was updated successfully, but these errors were encountered: