From f6207639ac319374075bd24c902c88e744cda354 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Wed, 8 Nov 2023 20:51:04 +0000 Subject: [PATCH 1/3] add column.shift --- .../dataframe_api/column_object.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/API_specification/dataframe_api/column_object.py b/spec/API_specification/dataframe_api/column_object.py index 6a83bbce..fed6da50 100644 --- a/spec/API_specification/dataframe_api/column_object.py +++ b/spec/API_specification/dataframe_api/column_object.py @@ -811,6 +811,19 @@ def rename(self, name: str) -> Self: """ ... + def shift(self, offset: int, *, fill_value: Scalar | NullType) -> Self: + """Shift values by `offset` positions, filling missing values with `fill_value`. + + For example, if the original column contains values `[1, 4, 2]`, then: + + - `.shift(1)` will return `[null, 1, 4]`, + - `.shift(-1)` will return `[4, 2, null]`, + - `.shift(1, fill_value=999)` will return `[999, 1, 4]`, + """ + ... + + # --- temporal methods --- + def year(self) -> Self: """Return 'year' component of each element of `Date` and `Datetime` columns. From 7e42254a309f15dacf8253fbfdd7cdb19c1cc423 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Wed, 8 Nov 2023 20:57:10 +0000 Subject: [PATCH 2/3] extra docs --- spec/API_specification/dataframe_api/column_object.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/API_specification/dataframe_api/column_object.py b/spec/API_specification/dataframe_api/column_object.py index fed6da50..497b52c8 100644 --- a/spec/API_specification/dataframe_api/column_object.py +++ b/spec/API_specification/dataframe_api/column_object.py @@ -819,6 +819,14 @@ def shift(self, offset: int, *, fill_value: Scalar | NullType) -> Self: - `.shift(1)` will return `[null, 1, 4]`, - `.shift(-1)` will return `[4, 2, null]`, - `.shift(1, fill_value=999)` will return `[999, 1, 4]`, + + Parameters + ---------- + offset + How many positions to shift by. + fill_value + Value to use for filling missing values. Must be of the Python + scalar type matching the dtype of the column. """ ... From 475ac45c27b14b96ac1f29bddd208735bce5c2f4 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Tue, 14 Nov 2023 08:09:27 +0000 Subject: [PATCH 3/3] formatting, remove fill_value --- .../API_specification/dataframe_api/column_object.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/spec/API_specification/dataframe_api/column_object.py b/spec/API_specification/dataframe_api/column_object.py index 497b52c8..79db7699 100644 --- a/spec/API_specification/dataframe_api/column_object.py +++ b/spec/API_specification/dataframe_api/column_object.py @@ -811,22 +811,18 @@ def rename(self, name: str) -> Self: """ ... - def shift(self, offset: int, *, fill_value: Scalar | NullType) -> Self: - """Shift values by `offset` positions, filling missing values with `fill_value`. + def shift(self, offset: int) -> Self: + """Shift values by `offset` positions, filling missing values with `null`. For example, if the original column contains values `[1, 4, 2]`, then: - `.shift(1)` will return `[null, 1, 4]`, - `.shift(-1)` will return `[4, 2, null]`, - - `.shift(1, fill_value=999)` will return `[999, 1, 4]`, Parameters ---------- - offset - How many positions to shift by. - fill_value - Value to use for filling missing values. Must be of the Python - scalar type matching the dtype of the column. + offset + How many positions to shift by. """ ...