@@ -74,14 +74,9 @@ def from_job(
7474 )
7575
7676 if cell_execution_count is None :
77- try :
78- import IPython
77+ from bigframes .core .utils import get_ipython_execution_count
7978
80- ipy = IPython .get_ipython ()
81- if ipy is not None and hasattr (ipy , "execution_count" ):
82- cell_execution_count = ipy .execution_count
83- except (ImportError , NameError ):
84- pass
79+ cell_execution_count = get_ipython_execution_count ()
8580
8681 metadata = cls (
8782 job_id = query_job .job_id ,
@@ -147,14 +142,9 @@ def from_row_iterator(
147142 )
148143
149144 if cell_execution_count is None :
150- try :
151- import IPython
145+ from bigframes .core .utils import get_ipython_execution_count
152146
153- ipy = IPython .get_ipython ()
154- if ipy is not None and hasattr (ipy , "execution_count" ):
155- cell_execution_count = ipy .execution_count
156- except (ImportError , NameError ):
157- pass
147+ cell_execution_count = get_ipython_execution_count ()
158148
159149 # fmt: off
160150 return cls (
@@ -328,14 +318,9 @@ def on_event(self, envelope: Any):
328318 self .bytes_processed += bytes_processed
329319
330320 if cell_execution_count is None :
331- try :
332- import IPython
333-
334- ipy = IPython .get_ipython ()
335- if ipy is not None and hasattr (ipy , "execution_count" ):
336- cell_execution_count = ipy .execution_count
337- except (ImportError , NameError ):
338- pass
321+ from bigframes .core .utils import get_ipython_execution_count
322+
323+ cell_execution_count = get_ipython_execution_count ()
339324
340325 metadata = JobMetadata (
341326 job_type = "polars" ,
0 commit comments