File tree Expand file tree Collapse file tree 1 file changed +5
-10
lines changed
Expand file tree Collapse file tree 1 file changed +5
-10
lines changed Original file line number Diff line number Diff line change @@ -224,14 +224,9 @@ def df_to_html(df: IntoFrame, maxrows: int = 5) -> str:
224224 HTML string representation of the table
225225
226226 """
227- df_short : nw .DataFrame [Any ]
228-
229- if isinstance (df , nw .LazyFrame ):
230- ndf_eager = df .collect ()
231- df_short = df .head (maxrows ).collect ()
232- elif isinstance (df , nw .DataFrame ):
233- ndf_eager = df
234- df_short = df .head (maxrows )
227+ if isinstance (df , (nw .LazyFrame , nw .DataFrame )):
228+ df_short = df .lazy ().head (maxrows ).collect ()
229+ nrow_full = df .lazy ().select (nw .len ()).collect ().item ()
235230 else :
236231 raise TypeError ("df must be a Narwhals DataFrame or LazyFrame" )
237232
@@ -242,9 +237,9 @@ def df_to_html(df: IntoFrame, maxrows: int = 5) -> str:
242237 )
243238
244239 # Add note about truncated rows if needed
245- if len (df_short ) != len ( ndf_eager ) :
240+ if len (df_short ) != nrow_full :
246241 rows_notice = (
247- f"\n \n (Showing only the first { maxrows } rows out of { len ( ndf_eager ) } .)\n "
242+ f"\n \n (Showing only the first { maxrows } rows out of { nrow_full } .)\n "
248243 )
249244 else :
250245 rows_notice = ""
You can’t perform that action at this time.
0 commit comments