Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions janitor/functions/add_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ def add_column(

nrows = len(df)

if fill_remaining:
warnings.warn("The fill_remaining parameter is no longer being used")

if hasattr(value, "__len__") and not isinstance(value, (str, bytes, bytearray)):
len_value = len(value)

Expand All @@ -114,18 +117,18 @@ def add_column(
if not len_value:
raise ValueError("`value` has to be an iterable of minimum length 1")

elif fill_remaining:
# relevant if a scalar val was passed, yet fill_remaining == True
len_value = 1
value = [value]

df = df.copy()
if fill_remaining:
#automatic fill remaining
times_to_loop = int(np.ceil(nrows / len_value))
fill_values = list(value) * times_to_loop
df[column_name] = fill_values[:nrows]
else:
df[column_name] = value

else
raise NotImplementedError("Bytes and Bytearrays are not currently implemented for add_column")

df = df.copy()




return df

Expand Down
Loading