Skip to content

Commit

Permalink
py: default sample n param to 1 (#3090)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer committed Apr 8, 2022
1 parent 91d7a0c commit ca5208f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions py-polars/polars/internals/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4763,9 +4763,13 @@ def sample(
└─────┴─────┴─────┘
"""
if n is not None:
return self._from_pydf(self._df.sample_n(n, with_replacement, seed))
return self._from_pydf(self._df.sample_frac(frac, with_replacement, seed))
if n is None and frac is not None:
return self._from_pydf(self._df.sample_frac(frac, with_replacement, seed))

if n is None:
n = 1

return self._from_pydf(self._df.sample_n(n, with_replacement, seed))

def fold(
self, operation: Callable[["pli.Series", "pli.Series"], "pli.Series"]
Expand Down
10 changes: 7 additions & 3 deletions py-polars/polars/internals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3045,9 +3045,13 @@ def sample(
]
"""
if n is not None:
return wrap_s(self._s.sample_n(n, with_replacement, seed))
return wrap_s(self._s.sample_frac(frac, with_replacement, seed))
if n is None and frac is not None:
return wrap_s(self._s.sample_frac(frac, with_replacement, seed))

if n is None:
n = 1

return wrap_s(self._s.sample_n(n, with_replacement, seed))

def peak_max(self) -> "Series":
"""
Expand Down

0 comments on commit ca5208f

Please sign in to comment.