@@ -62,8 +62,8 @@ class RaffaPolarsSeriesUtils:
6262 The ``.raffa`` namespace on a :class:`polars.Series`.
6363
6464 Registered automatically when :mod:`raffalib.polars` is imported. Provides
65- STATA-like change logging (:meth:`startlog` / :meth:`endlog`) and tabulation
66- helpers (:meth:`freq`, :meth:`crosstab`).
65+ STATA-like change logging (:meth:`startlog` / :meth:`endlog` / :meth:`midlog`)
66+ and tabulation helpers (:meth:`freq`, :meth:`crosstab`).
6767 """
6868
6969 def __init__ (self , series : pl .Series ):
@@ -125,6 +125,23 @@ def endlog(self, custom_msg: str | None = None, timeit: bool = True) -> pl.Serie
125125 logger .info (msg )
126126 return self ._series
127127
128+ def midlog (
129+ self , custom_msg : str | None = None , timeit : bool = True , clone : bool = False
130+ ) -> pl .Series :
131+ """
132+ Alias for `.endlog().startlog(clone=clone)`.
133+
134+ :param custom_msg: A custom message to log before the actual log
135+ :type custom_msg: str | None
136+ :param timeit: Log the time it took for the operation
137+ :type timeit: bool
138+ :param clone: Forwarded to the restarted ``startlog``: clone the data so
139+ the next segment can detect value-level changes when the shape is
140+ unchanged.
141+ :type clone: bool
142+ """
143+ return self .endlog (custom_msg , timeit = timeit ).raffa .startlog (clone = clone )
144+
128145 def freq (self ) -> pl .DataFrame :
129146 """
130147 Frequency table for the Series.
@@ -183,9 +200,9 @@ class RaffaPolarsDataFrameUtils:
183200 The ``.raffa`` namespace on a :class:`polars.DataFrame`.
184201
185202 Registered automatically when :mod:`raffalib.polars` is imported. Provides
186- STATA-like change logging (:meth:`startlog` / :meth:`endlog`), a logging
187- :meth:`join` wrapper, tabulation helpers (:meth:`freq`, :meth:`crosstab`) ,
188- and :meth:`to_docx` export.
203+ STATA-like change logging (:meth:`startlog` / :meth:`endlog` / :meth:`midlog`),
204+ a logging :meth:`join` wrapper, tabulation helpers (:meth:`freq`,
205+ :meth:`crosstab`), and :meth:`to_docx` export.
189206 """
190207
191208 def __init__ (self , df : pl .DataFrame ):
@@ -254,6 +271,26 @@ def endlog(
254271 logger .info (msg )
255272 return self ._df
256273
274+ def midlog (
275+ self ,
276+ custom_msg : str | None = None ,
277+ timeit : bool = True ,
278+ clone : bool = False ,
279+ ) -> pl .DataFrame :
280+ """
281+ Alias for `.endlog().startlog(clone=clone)`.
282+
283+ :param custom_msg: A custom message to log before the actual log
284+ :type custom_msg: str | None
285+ :param timeit: Log the time it took for the operation
286+ :type timeit: bool
287+ :param clone: Forwarded to the restarted ``startlog``: clone the data so
288+ the next segment can detect value-level changes when the shape is
289+ unchanged.
290+ :type clone: bool
291+ """
292+ return self .endlog (custom_msg , timeit = timeit ).raffa .startlog (clone = clone )
293+
257294 def replace_string_with_null (self , s ):
258295 """
259296 Replace a sentinel string with null across all string columns.
0 commit comments