idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
35,000 | def getPageImageList ( self , pno ) : if self . isClosed or self . isEncrypted : raise ValueError ( "operation illegal for closed / encrypted doc" ) if self . isPDF : return self . _getPageInfo ( pno , 2 ) return [ ] | Retrieve a list of images used on a page . |
35,001 | def copyPage ( self , pno , to = - 1 ) : pl = list ( range ( len ( self ) ) ) if pno < 0 or pno > pl [ - 1 ] : raise ValueError ( "'from' page number out of range" ) if to < - 1 or to > pl [ - 1 ] : raise ValueError ( "'to' page number out of range" ) if to == - 1 : pl . append ( pno ) else : pl . insert ( to , pno ) r... | Copy a page to before some other page of the document . Specify to = - 1 to copy after last page . |
35,002 | def movePage ( self , pno , to = - 1 ) : pl = list ( range ( len ( self ) ) ) if pno < 0 or pno > pl [ - 1 ] : raise ValueError ( "'from' page number out of range" ) if to < - 1 or to > pl [ - 1 ] : raise ValueError ( "'to' page number out of range" ) pl . remove ( pno ) if to == - 1 : pl . append ( pno ) else : pl . i... | Move a page to before some other page of the document . Specify to = - 1 to move after last page . |
35,003 | def deletePage ( self , pno = - 1 ) : pl = list ( range ( len ( self ) ) ) if pno < - 1 or pno > pl [ - 1 ] : raise ValueError ( "page number out of range" ) if pno >= 0 : pl . remove ( pno ) else : pl . remove ( pl [ - 1 ] ) return self . select ( pl ) | Delete a page from the document . First page is 0 last page is - 1 . |
35,004 | def deletePageRange ( self , from_page = - 1 , to_page = - 1 ) : pl = list ( range ( len ( self ) ) ) f = from_page t = to_page if f == - 1 : f = pl [ - 1 ] if t == - 1 : t = pl [ - 1 ] if not 0 <= f <= t <= pl [ - 1 ] : raise ValueError ( "page number(s) out of range" ) for i in range ( f , t + 1 ) : pl . remove ( i )... | Delete pages from the document . First page is 0 last page is - 1 . |
35,005 | def _forget_page ( self , page ) : pid = id ( page ) if pid in self . _page_refs : self . _page_refs [ pid ] = None | Remove a page from document page dict . |
35,006 | def _reset_page_refs ( self ) : if self . isClosed : return for page in self . _page_refs . values ( ) : if page : page . _erase ( ) page = None self . _page_refs . clear ( ) | Invalidate all pages in document dictionary . |
35,007 | def addLineAnnot ( self , p1 , p2 ) : CheckParent ( self ) val = _fitz . Page_addLineAnnot ( self , p1 , p2 ) if not val : return val . thisown = True val . parent = weakref . proxy ( self ) self . _annot_refs [ id ( val ) ] = val return val | Add Line annot for points p1 and p2 . |
35,008 | def addTextAnnot ( self , point , text ) : CheckParent ( self ) val = _fitz . Page_addTextAnnot ( self , point , text ) if not val : return val . thisown = True val . parent = weakref . proxy ( self ) self . _annot_refs [ id ( val ) ] = val return val | Add a sticky note at position point . |
35,009 | def addInkAnnot ( self , list ) : CheckParent ( self ) val = _fitz . Page_addInkAnnot ( self , list ) if not val : return val . thisown = True val . parent = weakref . proxy ( self ) self . _annot_refs [ id ( val ) ] = val return val | Add a handwriting as a list of list of point - likes . Each sublist forms an independent stroke . |
35,010 | def addStampAnnot ( self , rect , stamp = 0 ) : CheckParent ( self ) val = _fitz . Page_addStampAnnot ( self , rect , stamp ) if not val : return val . thisown = True val . parent = weakref . proxy ( self ) self . _annot_refs [ id ( val ) ] = val return val | Add a rubber stamp in a rectangle . |
35,011 | def addFileAnnot ( self , point , buffer , filename , ufilename = None , desc = None ) : CheckParent ( self ) val = _fitz . Page_addFileAnnot ( self , point , buffer , filename , ufilename , desc ) if not val : return val . thisown = True val . parent = weakref . proxy ( self ) self . _annot_refs [ id ( val ) ] = val r... | Add a FileAttachment annotation at location point . |
35,012 | def addStrikeoutAnnot ( self , rect ) : CheckParent ( self ) val = _fitz . Page_addStrikeoutAnnot ( self , rect ) if not val : return val . thisown = True val . parent = weakref . proxy ( self ) self . _annot_refs [ id ( val ) ] = val return val | Strike out content in a rectangle or quadrilateral . |
35,013 | def addUnderlineAnnot ( self , rect ) : CheckParent ( self ) val = _fitz . Page_addUnderlineAnnot ( self , rect ) if not val : return val . thisown = True val . parent = weakref . proxy ( self ) self . _annot_refs [ id ( val ) ] = val return val | Underline content in a rectangle or quadrilateral . |
35,014 | def addSquigglyAnnot ( self , rect ) : CheckParent ( self ) val = _fitz . Page_addSquigglyAnnot ( self , rect ) if not val : return val . thisown = True val . parent = weakref . proxy ( self ) self . _annot_refs [ id ( val ) ] = val return val | Wavy underline content in a rectangle or quadrilateral . |
35,015 | def addHighlightAnnot ( self , rect ) : CheckParent ( self ) val = _fitz . Page_addHighlightAnnot ( self , rect ) if not val : return val . thisown = True val . parent = weakref . proxy ( self ) self . _annot_refs [ id ( val ) ] = val return val | Highlight content in a rectangle or quadrilateral . |
35,016 | def addRectAnnot ( self , rect ) : CheckParent ( self ) val = _fitz . Page_addRectAnnot ( self , rect ) if not val : return val . thisown = True val . parent = weakref . proxy ( self ) self . _annot_refs [ id ( val ) ] = val return val | Add a Rectangle annotation . |
35,017 | def addCircleAnnot ( self , rect ) : CheckParent ( self ) val = _fitz . Page_addCircleAnnot ( self , rect ) if not val : return val . thisown = True val . parent = weakref . proxy ( self ) self . _annot_refs [ id ( val ) ] = val return val | Add a Circle annotation . |
35,018 | def addPolylineAnnot ( self , points ) : CheckParent ( self ) val = _fitz . Page_addPolylineAnnot ( self , points ) if not val : return val . thisown = True val . parent = weakref . proxy ( self ) self . _annot_refs [ id ( val ) ] = val return val | Add a Polyline annotation for a sequence of points . |
35,019 | def addPolygonAnnot ( self , points ) : CheckParent ( self ) val = _fitz . Page_addPolygonAnnot ( self , points ) if not val : return val . thisown = True val . parent = weakref . proxy ( self ) self . _annot_refs [ id ( val ) ] = val return val | Add a Polygon annotation for a sequence of points . |
35,020 | def addFreetextAnnot ( self , rect , text , fontsize = 12 , fontname = None , color = None , rotate = 0 ) : CheckParent ( self ) val = _fitz . Page_addFreetextAnnot ( self , rect , text , fontsize , fontname , color , rotate ) if not val : return val . thisown = True val . parent = weakref . proxy ( self ) self . _anno... | Add a FreeText annotation in rectangle rect . |
35,021 | def addWidget ( self , widget ) : CheckParent ( self ) doc = self . parent if not doc . isPDF : raise ValueError ( "not a PDF" ) widget . _validate ( ) xref = 0 ff = doc . FormFonts if not widget . text_font : widget . text_font = "Helv" if not widget . text_font in ff : if not doc . isFormPDF or not ff : xref = doc . ... | Add a form field . |
35,022 | def firstAnnot ( self ) : CheckParent ( self ) val = _fitz . Page_firstAnnot ( self ) if val : val . thisown = True val . parent = weakref . proxy ( self ) self . _annot_refs [ id ( val ) ] = val return val | Points to first annotation on page |
35,023 | def deleteLink ( self , linkdict ) : CheckParent ( self ) val = _fitz . Page_deleteLink ( self , linkdict ) if linkdict [ "xref" ] == 0 : return linkid = linkdict [ "id" ] try : linkobj = self . _annot_refs [ linkid ] linkobj . _erase ( ) except : pass return val | Delete link if PDF |
35,024 | def deleteAnnot ( self , fannot ) : CheckParent ( self ) val = _fitz . Page_deleteAnnot ( self , fannot ) if val : val . thisown = True val . parent = weakref . proxy ( self ) val . parent . _annot_refs [ id ( val ) ] = val fannot . _erase ( ) return val | Delete annot if PDF and return next one |
35,025 | def _forget_annot ( self , annot ) : aid = id ( annot ) if aid in self . _annot_refs : self . _annot_refs [ aid ] = None | Remove an annot from reference dictionary . |
35,026 | def rect ( self ) : CheckParent ( self ) val = _fitz . Annot_rect ( self ) val = Rect ( val ) return val | Rectangle containing the annot |
35,027 | def fileUpd ( self , buffer = None , filename = None , ufilename = None , desc = None ) : CheckParent ( self ) return _fitz . Annot_fileUpd ( self , buffer , filename , ufilename , desc ) | Update annotation attached file . |
35,028 | def dest ( self ) : if hasattr ( self , "parent" ) and self . parent is None : raise ValueError ( "orphaned object: parent is None" ) if self . parent . parent . isClosed or self . parent . parent . isEncrypted : raise ValueError ( "operation illegal for closed / encrypted doc" ) doc = self . parent . parent if self . ... | Create link destination details . |
35,029 | def measure_string ( self , text , fontname , fontsize , encoding = 0 ) : return _fitz . Tools_measure_string ( self , text , fontname , fontsize , encoding ) | Measure length of a string for a Base14 font . |
35,030 | def _le_annot_parms ( self , annot , p1 , p2 ) : w = annot . border [ "width" ] sc = annot . colors [ "stroke" ] if not sc : sc = ( 0 , 0 , 0 ) scol = " " . join ( map ( str , sc ) ) + " RG\n" fc = annot . colors [ "fill" ] if not fc : fc = ( 0 , 0 , 0 ) fcol = " " . join ( map ( str , fc ) ) + " rg\n" nr = annot . rec... | Get common parameters for making line end symbols . |
35,031 | def pbis ( a ) : return ( math . cos ( 3 * a - math . pi ) , ( math . sin ( 3 * a - math . pi ) ) ) | End point of a reflected sun ray given an angle a . |
35,032 | def print_descr ( rect , annot ) : annot . parent . insertText ( rect . br + ( 10 , 0 ) , "'%s' annotation" % annot . type [ 1 ] , color = red ) | Print a short description to the right of an annot rect . |
35,033 | def recoverpix ( doc , item ) : x = item [ 0 ] s = item [ 1 ] try : pix1 = fitz . Pixmap ( doc , x ) except : print ( "xref %i " % x + doc . _getGCTXerrmsg ( ) ) return None if s == 0 : return pix1 try : pix2 = fitz . Pixmap ( doc , s ) except : print ( "cannot create mask %i for image xref %i" % ( s , x ) ) return pix... | Return pixmap for item which is a list of 2 xref numbers . Second xref is that of an smask if > 0 . Return None for any error . |
35,034 | def on_update_page_links ( self , evt ) : if not self . update_links : evt . Skip ( ) return pg = self . doc [ getint ( self . TextToPage . Value ) - 1 ] for i in range ( len ( self . page_links ) ) : l = self . page_links [ i ] if l . get ( "update" , False ) : if l [ "xref" ] == 0 : pg . insertLink ( l ) elif l [ "ki... | Perform PDF update of changed links . |
35,035 | def Rect_to_wxRect ( self , fr ) : r = ( fr * self . zoom ) . irect return wx . Rect ( r . x0 , r . y0 , r . width , r . height ) | Return a zoomed wx . Rect for given fitz . Rect . |
35,036 | def wxRect_to_Rect ( self , wr ) : r = fitz . Rect ( wr . x , wr . y , wr . x + wr . width , wr . y + wr . height ) return r * self . shrink | Return a shrunk fitz . Rect for given wx . Rect . |
35,037 | def is_in_free_area ( self , nr , ok = - 1 ) : for i , r in enumerate ( self . link_rects ) : if r . Intersects ( nr ) and i != ok : return False bmrect = wx . Rect ( 0 , 0 , dlg . bitmap . Size [ 0 ] , dlg . bitmap . Size [ 1 ] ) return bmrect . Contains ( nr ) | Determine if rect covers a free area inside the bitmap . |
35,038 | def get_linkrect_idx ( self , pos ) : for i , r in enumerate ( self . link_rects ) : if r . Contains ( pos ) : return i return - 1 | Determine if cursor is inside one of the link hot spots . |
35,039 | def get_bottomrect_idx ( self , pos ) : for i , r in enumerate ( self . link_bottom_rects ) : if r . Contains ( pos ) : return i return - 1 | Determine if cursor is on bottom right corner of a hot spot . |
35,040 | def getTextWords ( page ) : CheckParent ( page ) dl = page . getDisplayList ( ) tp = dl . getTextPage ( ) l = tp . _extractTextWords_AsList ( ) del dl del tp return l | Return the text words as a list with the bbox for each word . |
35,041 | def getText ( page , output = "text" ) : CheckParent ( page ) dl = page . getDisplayList ( ) formats = ( "text" , "html" , "json" , "xml" , "xhtml" , "dict" , "rawdict" ) images = ( 0 , 1 , 1 , 0 , 1 , 1 , 1 ) try : f = formats . index ( output . lower ( ) ) except : f = 0 flags = TEXT_PRESERVE_LIGATURES | TEXT_PRESERV... | Extract a document page s text . |
35,042 | def getPagePixmap ( doc , pno , matrix = None , colorspace = csRGB , clip = None , alpha = True ) : return doc [ pno ] . getPixmap ( matrix = matrix , colorspace = colorspace , clip = clip , alpha = alpha ) | Create pixmap of document page by page number . |
35,043 | def getToC ( doc , simple = True ) : def recurse ( olItem , liste , lvl ) : while olItem : if olItem . title : title = olItem . title else : title = " " if not olItem . isExternal : if olItem . uri : page = olItem . page + 1 else : page = - 1 else : page = - 1 if not simple : link = getLinkDict ( olItem ) liste . appen... | Create a table of contents . |
35,044 | def updateLink ( page , lnk ) : CheckParent ( page ) annot = getLinkText ( page , lnk ) if annot == "" : raise ValueError ( "link kind not supported" ) page . parent . _updateObject ( lnk [ "xref" ] , annot , page = page ) return | Update a link on the current page . |
35,045 | def insertLink ( page , lnk , mark = True ) : CheckParent ( page ) annot = getLinkText ( page , lnk ) if annot == "" : raise ValueError ( "link kind not supported" ) page . _addAnnot_FromString ( [ annot ] ) return | Insert a new link for the current page . |
35,046 | def newPage ( doc , pno = - 1 , width = 595 , height = 842 ) : doc . _newPage ( pno , width = width , height = height ) return doc [ pno ] | Create and return a new page object . |
35,047 | def insertPage ( doc , pno , text = None , fontsize = 11 , width = 595 , height = 842 , fontname = "helv" , fontfile = None , color = None , ) : page = doc . newPage ( pno = pno , width = width , height = height ) if not bool ( text ) : return 0 rc = page . insertText ( ( 50 , 72 ) , text , fontsize = fontsize , fontna... | Create a new PDF page and insert some text . |
35,048 | def drawSquiggle ( page , p1 , p2 , breadth = 2 , color = None , dashes = None , width = 1 , roundCap = False , overlay = True , morph = None ) : img = page . newShape ( ) p = img . drawSquiggle ( Point ( p1 ) , Point ( p2 ) , breadth = breadth ) img . finish ( color = color , dashes = dashes , width = width , closePat... | Draw a squiggly line from point p1 to point p2 . |
35,049 | def drawQuad ( page , quad , color = None , fill = None , dashes = None , width = 1 , roundCap = False , morph = None , overlay = True ) : img = page . newShape ( ) Q = img . drawQuad ( Quad ( quad ) ) img . finish ( color = color , fill = fill , dashes = dashes , width = width , roundCap = roundCap , morph = morph ) i... | Draw a quadrilateral . |
35,050 | def drawPolyline ( page , points , color = None , fill = None , dashes = None , width = 1 , morph = None , roundCap = False , overlay = True , closePath = False ) : img = page . newShape ( ) Q = img . drawPolyline ( points ) img . finish ( color = color , fill = fill , dashes = dashes , width = width , roundCap = round... | Draw multiple connected line segments . |
35,051 | def drawBezier ( page , p1 , p2 , p3 , p4 , color = None , fill = None , dashes = None , width = 1 , morph = None , closePath = False , roundCap = False , overlay = True ) : img = page . newShape ( ) Q = img . drawBezier ( Point ( p1 ) , Point ( p2 ) , Point ( p3 ) , Point ( p4 ) ) img . finish ( color = color , fill =... | Draw a general cubic Bezier curve from p1 to p4 using control points p2 and p3 . |
35,052 | def getColor ( name ) : try : c = getColorInfoList ( ) [ getColorList ( ) . index ( name . upper ( ) ) ] return ( c [ 1 ] / 255. , c [ 2 ] / 255. , c [ 3 ] / 255. ) except : return ( 1 , 1 , 1 ) | Retrieve RGB color in PDF format by name . |
35,053 | def getColorHSV ( name ) : try : x = getColorInfoList ( ) [ getColorList ( ) . index ( name . upper ( ) ) ] except : return ( - 1 , - 1 , - 1 ) r = x [ 1 ] / 255. g = x [ 2 ] / 255. b = x [ 3 ] / 255. cmax = max ( r , g , b ) V = round ( cmax * 100 , 1 ) cmin = min ( r , g , b ) delta = cmax - cmin if delta == 0 : hue ... | Retrieve the hue saturation value triple of a color name . |
35,054 | def horizontal_angle ( C , P ) : S = Point ( P - C ) . unit alfa = math . asin ( abs ( S . y ) ) if S . x < 0 : if S . y <= 0 : alfa = - ( math . pi - alfa ) else : alfa = math . pi - alfa else : if S . y >= 0 : pass else : alfa = - alfa return alfa | Return the angle to the horizontal for the connection from C to P . This uses the arcus sine function and resolves its inherent ambiguity by looking up in which quadrant vector S = P - C is located . |
35,055 | def drawLine ( self , p1 , p2 ) : p1 = Point ( p1 ) p2 = Point ( p2 ) if not ( self . lastPoint == p1 ) : self . draw_cont += "%g %g m\n" % JM_TUPLE ( p1 * self . ipctm ) self . lastPoint = p1 self . updateRect ( p1 ) self . draw_cont += "%g %g l\n" % JM_TUPLE ( p2 * self . ipctm ) self . updateRect ( p2 ) self . lastP... | Draw a line between two points . |
35,056 | def drawPolyline ( self , points ) : for i , p in enumerate ( points ) : if i == 0 : if not ( self . lastPoint == Point ( p ) ) : self . draw_cont += "%g %g m\n" % JM_TUPLE ( Point ( p ) * self . ipctm ) self . lastPoint = Point ( p ) else : self . draw_cont += "%g %g l\n" % JM_TUPLE ( Point ( p ) * self . ipctm ) self... | Draw several connected line segments . |
35,057 | def drawBezier ( self , p1 , p2 , p3 , p4 ) : p1 = Point ( p1 ) p2 = Point ( p2 ) p3 = Point ( p3 ) p4 = Point ( p4 ) if not ( self . lastPoint == p1 ) : self . draw_cont += "%g %g m\n" % JM_TUPLE ( p1 * self . ipctm ) self . draw_cont += "%g %g %g %g %g %g c\n" % JM_TUPLE ( list ( p2 * self . ipctm ) + list ( p3 * sel... | Draw a standard cubic Bezier curve . |
35,058 | def drawOval ( self , tetra ) : if len ( tetra ) != 4 : raise ValueError ( "invalid arg length" ) if hasattr ( tetra [ 0 ] , "__float__" ) : q = Rect ( tetra ) . quad else : q = Quad ( tetra ) mt = q . ul + ( q . ur - q . ul ) * 0.5 mr = q . ur + ( q . lr - q . ur ) * 0.5 mb = q . ll + ( q . lr - q . ll ) * 0.5 ml = q ... | Draw an ellipse inside a tetrapod . |
35,059 | def drawCurve ( self , p1 , p2 , p3 ) : kappa = 0.55228474983 p1 = Point ( p1 ) p2 = Point ( p2 ) p3 = Point ( p3 ) k1 = p1 + ( p2 - p1 ) * kappa k2 = p3 + ( p2 - p3 ) * kappa return self . drawBezier ( p1 , k1 , k2 , p3 ) | Draw a curve between points using one control point . |
35,060 | def drawQuad ( self , quad ) : q = Quad ( quad ) return self . drawPolyline ( [ q . ul , q . ll , q . lr , q . ur , q . ul ] ) | Draw a Quad . |
35,061 | def drawZigzag ( self , p1 , p2 , breadth = 2 ) : p1 = Point ( p1 ) p2 = Point ( p2 ) S = p2 - p1 rad = abs ( S ) cnt = 4 * int ( round ( rad / ( 4 * breadth ) , 0 ) ) if cnt < 4 : raise ValueError ( "points too close" ) mb = rad / cnt matrix = TOOLS . _hor_matrix ( p1 , p2 ) i_mat = ~ matrix points = [ ] for i in rang... | Draw a zig - zagged line from p1 to p2 . |
35,062 | def drawSquiggle ( self , p1 , p2 , breadth = 2 ) : p1 = Point ( p1 ) p2 = Point ( p2 ) S = p2 - p1 rad = abs ( S ) cnt = 4 * int ( round ( rad / ( 4 * breadth ) , 0 ) ) if cnt < 4 : raise ValueError ( "points too close" ) mb = rad / cnt matrix = TOOLS . _hor_matrix ( p1 , p2 ) i_mat = ~ matrix k = 2.4142135623765633 p... | Draw a squiggly line from p1 to p2 . |
35,063 | def finish ( self , width = 1 , color = None , fill = None , roundCap = False , dashes = None , even_odd = False , morph = None , closePath = True ) : if self . draw_cont == "" : return color_str = ColorCode ( color , "c" ) fill_str = ColorCode ( fill , "f" ) if width != 1 : self . draw_cont += "%g w\n" % width if roun... | Finish the current drawing segment . |
35,064 | def set_float ( self , option , value ) : if not isinstance ( value , float ) : raise TypeError ( "Value must be a float" ) self . options [ option ] = value | Set a float option . |
35,065 | def set_integer ( self , option , value ) : try : int_value = int ( value ) except ValueError as err : print ( err . args ) self . options [ option ] = value | Set an integer option . |
35,066 | def set_boolean ( self , option , value ) : if not isinstance ( value , bool ) : raise TypeError ( "%s must be a boolean" % option ) self . options [ option ] = str ( value ) . lower ( ) | Set a boolean option . |
35,067 | def set_string ( self , option , value ) : if not isinstance ( value , str ) : raise TypeError ( "%s must be a string" % option ) self . options [ option ] = value | Set a string option . |
35,068 | def custom_line_color_map ( self , values ) : if not isinstance ( values , list ) : raise TypeError ( "custom_line_color_map must be a list" ) self . options [ "custom_line_color_map" ] = values | Set the custom line color map . |
35,069 | def legend ( self , values ) : if not isinstance ( values , list ) : raise TypeError ( "legend must be a list of labels" ) self . options [ "legend" ] = values | Set the legend labels . |
35,070 | def markers ( self , values ) : if not isinstance ( values , list ) : raise TypeError ( "Markers must be a list of objects" ) self . options [ "markers" ] = values | Set the markers . |
35,071 | def get ( self ) : return { k : v for k , v in list ( self . options . items ( ) ) if k in self . _allowed_graphics } | Get graphics options . |
35,072 | def apply_filters ( df , filters ) : idx = pd . Series ( [ True ] * df . shape [ 0 ] ) for k , v in list ( filters . items ( ) ) : if k not in df . columns : continue idx &= ( df [ k ] == v ) return df . loc [ idx ] | Basic filtering for a dataframe . |
35,073 | def format_row ( row , bounds , columns ) : for c in columns : if c not in row : continue if "format" in columns [ c ] : row [ c ] = columns [ c ] [ "format" ] % row [ c ] if c in bounds : b = bounds [ c ] row [ c ] = [ b [ "min" ] , row [ b [ "lower" ] ] , row [ b [ "upper" ] ] , b [ "max" ] ] return row | Formats a single row of the dataframe |
35,074 | def to_json ( df , columns , confidence = { } ) : records = [ ] display_cols = list ( columns . keys ( ) ) if not display_cols : display_cols = list ( df . columns ) bounds = { } for c in confidence : bounds [ c ] = { "min" : df [ confidence [ c ] [ "lower" ] ] . min ( ) , "max" : df [ confidence [ c ] [ "upper" ] ] . ... | Transforms dataframe to properly formatted json response |
35,075 | def get ( self ) : options = { } for x in [ self . axes , self . graphics , self . layout ] : for k , v in list ( x . get ( ) . items ( ) ) : options [ k ] = v return options | Return axes graphics and layout options . |
35,076 | def set_margin ( self , top = 40 , bottom = 30 , left = 50 , right = 10 , buffer_size = 8 ) : self . set_integer ( "top" , top ) self . set_integer ( "bottom" , bottom ) self . set_integer ( "left" , left ) self . set_integer ( "right" , right ) self . set_integer ( "buffer" , buffer_size ) | Set margin of the chart . |
35,077 | def set_size ( self , height = 220 , width = 350 , height_threshold = 120 , width_threshold = 160 ) : self . set_integer ( "height" , height ) self . set_integer ( "width" , width ) self . set_integer ( "small_height_threshold" , height_threshold ) self . set_integer ( "small_width_threshold" , width_threshold ) | Set the size of the chart . |
35,078 | def get ( self ) : return { k : v for k , v in list ( self . options . items ( ) ) if k in self . _allowed_layout } | Get layout options . |
35,079 | def format_props ( props , prop_template = "{{k}} = { {{v}} }" , delim = "\n" ) : vars_ = [ ] props_ = [ ] for k , v in list ( props . items ( ) ) : vars_ . append ( Template ( "var {{k}} = {{v}};" ) . render ( k = k , v = json . dumps ( v ) ) ) props_ . append ( Template ( prop_template ) . render ( k = k , v = k ) ) ... | Formats props for the React template . |
35,080 | def register_layouts ( layouts , app , url = "/api/props/" , brand = "Pyxley" ) : def props ( name ) : if name not in layouts : name = list ( layouts . keys ( ) ) [ 0 ] return jsonify ( { "layouts" : layouts [ name ] [ "layout" ] } ) def apps ( ) : paths = [ ] for i , k in enumerate ( layouts . keys ( ) ) : if i == 0 :... | register UILayout with the flask app |
35,081 | def register_route ( self , app ) : if "url" not in self . params [ "options" ] : raise Exception ( "Component does not have a URL property" ) if not hasattr ( self . route_func , "__call__" ) : raise Exception ( "No app route function supplied" ) app . add_url_rule ( self . params [ "options" ] [ "url" ] , self . para... | Register the api route function with the app . |
35,082 | def render ( self , path ) : return ReactComponent ( self . layout , self . src_file , self . component_id , props = self . props , static_path = path ) | Render the component to a javascript file . |
35,083 | def add_filter ( self , component , filter_group = "pyxley-filter" ) : if getattr ( component , "name" ) != "Filter" : raise Exception ( "Component is not an instance of Filter" ) if filter_group not in self . filters : self . filters [ filter_group ] = [ ] self . filters [ filter_group ] . append ( component ) | Add a filter to the layout . |
35,084 | def add_chart ( self , component ) : if getattr ( component , "name" ) != "Chart" : raise Exception ( "Component is not an instance of Chart" ) self . charts . append ( component ) | Add a chart to the layout . |
35,085 | def build_props ( self ) : props = { } if self . filters : props [ "filters" ] = { } for grp in self . filters : props [ "filters" ] [ grp ] = [ f . params for f in self . filters [ grp ] ] if self . charts : props [ "charts" ] = [ c . params for c in self . charts ] props [ "type" ] = self . layout return props | Build the props dictionary . |
35,086 | def assign_routes ( self , app ) : for grp in self . filters : for f in self . filters [ grp ] : if f . route_func : f . register_route ( app ) for c in self . charts : if c . route_func : c . register_route ( app ) | Register routes with the app . |
35,087 | def render_layout ( self , app , path , alias = None ) : self . assign_routes ( app ) return ReactComponent ( self . layout , self . src_file , self . component_id , props = self . build_props ( ) , static_path = path , alias = alias ) | Write to javascript . |
35,088 | def default_static_path ( ) : fdir = os . path . dirname ( __file__ ) return os . path . abspath ( os . path . join ( fdir , '../assets/' ) ) | Return the path to the javascript bundle |
35,089 | def default_template_path ( ) : fdir = os . path . dirname ( __file__ ) return os . path . abspath ( os . path . join ( fdir , '../assets/' ) ) | Return the path to the index . html |
35,090 | def set_xlim ( self , xlim ) : if len ( xlim ) != 2 : raise ValueError ( "xlim must contain two elements" ) if xlim [ 1 ] < xlim [ 0 ] : raise ValueError ( "Min must be less than Max" ) self . options [ "min_x" ] = xlim [ 0 ] self . options [ "max_x" ] = xlim [ 1 ] | Set x - axis limits . |
35,091 | def set_ylim ( self , ylim ) : if len ( ylim ) != 2 : raise ValueError ( "ylim must contain two elements" ) if ylim [ 1 ] < ylim [ 0 ] : raise ValueError ( "Min must be less than Max" ) self . options [ "min_y" ] = ylim [ 0 ] self . options [ "max_y" ] = ylim [ 1 ] | Set y - axis limits . |
35,092 | def get ( self ) : return { k : v for k , v in list ( self . options . items ( ) ) if k in self . _allowed_axes } | Retrieve options set by user . |
35,093 | def line_plot ( df , xypairs , mode , layout = { } , config = _BASE_CONFIG ) : if df . empty : return { "x" : [ ] , "y" : [ ] , "mode" : mode } _data = [ ] for x , y in xypairs : if ( x in df . columns ) and ( y in df . columns ) : _data . append ( { "x" : df [ x ] . values . tolist ( ) , "y" : df [ y ] . values . toli... | basic line plot |
35,094 | def to_json ( df , values ) : records = [ ] if df . empty : return { "data" : [ ] } sum_ = float ( np . sum ( [ df [ c ] . iloc [ 0 ] for c in values ] ) ) for c in values : records . append ( { "label" : values [ c ] , "value" : "%.2f" % np . around ( df [ c ] . iloc [ 0 ] / sum_ , decimals = 2 ) } ) return { "data" :... | Format output for the json response . |
35,095 | def to_json ( df , state_index , color_index , fills ) : records = { } for i , row in df . iterrows ( ) : records [ row [ state_index ] ] = { "fillKey" : row [ color_index ] } return { "data" : records , "fills" : fills } | Transforms dataframe to json response |
35,096 | def error_string ( mqtt_errno ) : if mqtt_errno == MQTT_ERR_SUCCESS : return "No error." elif mqtt_errno == MQTT_ERR_NOMEM : return "Out of memory." elif mqtt_errno == MQTT_ERR_PROTOCOL : return "A network protocol error occurred when communicating with the broker." elif mqtt_errno == MQTT_ERR_INVAL : return "Invalid f... | Return the error string associated with an mqtt error number . |
35,097 | def topic_matches_sub ( sub , topic ) : result = True multilevel_wildcard = False slen = len ( sub ) tlen = len ( topic ) if slen > 0 and tlen > 0 : if ( sub [ 0 ] == '$' and topic [ 0 ] != '$' ) or ( topic [ 0 ] == '$' and sub [ 0 ] != '$' ) : return False spos = 0 tpos = 0 while spos < slen and tpos < tlen : if sub [... | Check whether a topic matches a subscription . |
35,098 | def configIAMCredentials ( self , srcAWSAccessKeyID , srcAWSSecretAccessKey , srcAWSSessionToken ) : self . _AWSAccessKeyIDCustomConfig = srcAWSAccessKeyID self . _AWSSecretAccessKeyCustomConfig = srcAWSSecretAccessKey self . _AWSSessionTokenCustomConfig = srcAWSSessionToken | Make custom settings for IAM credentials for websocket connection srcAWSAccessKeyID - AWS IAM access key srcAWSSecretAccessKey - AWS IAM secret key srcAWSSessionToken - AWS Session Token |
35,099 | def loop ( self , timeout = 1.0 , max_packets = 1 ) : if timeout < 0.0 : raise ValueError ( 'Invalid timeout.' ) self . _current_out_packet_mutex . acquire ( ) self . _out_packet_mutex . acquire ( ) if self . _current_out_packet is None and len ( self . _out_packet ) > 0 : self . _current_out_packet = self . _out_packe... | Process network events . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.