@@ -245,6 +245,31 @@ define([
245
245
return label ;
246
246
}
247
247
248
+ /**
249
+ * Pack the code with ignoring the warnings
250
+ * @param {* } code
251
+ */
252
+ var ignoreWarning = function ( code ) {
253
+ var convertedCode = new com_String ( ) ;
254
+ convertedCode . appendLine ( 'import warnings' ) ;
255
+ convertedCode . appendLine ( 'from IPython.display import display' ) ;
256
+ convertedCode . appendLine ( 'with warnings.catch_warnings():' ) ;
257
+ convertedCode . appendLine ( " warnings.simplefilter('ignore')" ) ;
258
+ let codeLines = code . split ( '\n' ) ;
259
+ codeLines . forEach ( ( line , idx ) => {
260
+ if ( idx > 0 ) {
261
+ convertedCode . appendLine ( ) ;
262
+ }
263
+ if ( codeLines . length == idx + 1 ) {
264
+ // last line
265
+ convertedCode . appendFormat ( " display({0})" , line ) ;
266
+ } else {
267
+ convertedCode . appendFormat ( " {0}" , line ) ;
268
+ }
269
+ } ) ;
270
+ return convertedCode . toString ( ) ;
271
+ }
272
+
248
273
//============================================================================
249
274
// Cross-browser RegEx Split
250
275
//============================================================================
@@ -377,6 +402,7 @@ define([
377
402
setIsAPIListRunCode : setIsAPIListRunCode ,
378
403
getIsAPIListRunCode : getIsAPIListRunCode ,
379
404
safeString : safeString ,
405
+ ignoreWarning : ignoreWarning ,
380
406
381
407
regex_split : regex_split
382
408
}
0 commit comments