# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: 'Python 3.7.8 64-bit (''base'': conda)'
#     name: python3
# ---

# +
# https://tibble.tidyverse.org/reference/add_column.html

from datar import f
from datar.tibble import *
from datar.base import seq
from datar.core.exceptions import NameNonUniqueError

# %run nb_helpers.py
nb_header(add_column)
# -

df = tibble(x=seq(1,3), y=seq(3,1))
df >> add_column(z=seq(-1,1), w=0)

df >> add_column(z=seq(-1,1), _before=f.y)

# You can't overwrite existing columns
try:
    df >> add_column(x = seq(4,6))
except NameNonUniqueError as err:
    print(err)

# You can't create new observations
with try_catch():
    df >> add_column(z = seq(1,5))



StarcoderdataJupyterScriptsDedupFiltered