xhochy / fletcher

Pandas ExtensionDType/Array backed by Apache Arrow

Home Page:https://fletcher.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add str.center method

xhochy opened this issue · comments

  • ✔️ pandas function
  • ✔️ Python function
  • ❌ C++ STL function
  • ✔️ no need for a regular expression library
  • ✔️ no need for a Unicode database
  • ❌ cannot pre-compute output size without going over the data as some strings are wider then width (need no centering) and some aren't (need centering).

Pseudo-Code:

Inputs: width, fillchar

builder = StringBuilder()
for row in rows:
    if utf8_len(row) >= width:
        builder.append(row)
    else:
        n_missing = width - utf8_len(row)
        left = (n_missing // 2) + (n_missing % 2)
        right = (n_missing // 2)
        builder.add(fillchar * left + row + fillchar * right)