From 2a4290d4c62a5f3d62d440fa97ae9b4690539caf Mon Sep 17 00:00:00 2001 From: matthewkrausse <106627640+mattkrausse@users.noreply.github.com> Date: Fri, 23 Feb 2024 18:19:05 -0900 Subject: [PATCH 1/5] added head and tail methods to parsons table --- parsons/etl/etl.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/parsons/etl/etl.py b/parsons/etl/etl.py index f2b20e94fe..6c91deeb4d 100644 --- a/parsons/etl/etl.py +++ b/parsons/etl/etl.py @@ -9,6 +9,37 @@ class ETL(object): def __init__(self): pass + def head(self, n=5): + """ + Return the first n rows of the table + + `Args:` + n: int + The number of rows to return. Defaults to 5. + `Returns:` + `Parsons Table` + """ + + self.table = petl.head(self.table, n) + + return self + + def tail(self, n=5): + """ + Return the last n rows of the table. Defaults to 5. + + `Args:` + n: int + The number of rows to return + + `Returns:` + `Parsons Table` + """ + + self.table = petl.tail(self.table, n) + + return self + def add_column(self, column, value=None, index=None, if_exists="fail"): """ Add a column to your table @@ -724,7 +755,7 @@ def long_table( The new long table """ - if type(key) == str: + if type(key) is str: key = [key] lt = self.cut(*key, column) # Create a table of key and column From a885d118615bc56aa15fff3a6af9109fd3bd6bd9 Mon Sep 17 00:00:00 2001 From: matthewkrausse <106627640+mattkrausse@users.noreply.github.com> Date: Fri, 23 Feb 2024 18:19:30 -0900 Subject: [PATCH 2/5] adding tests and docs to head and tail --- docs/table.rst | 4 ++++ test/test_etl.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/docs/table.rst b/docs/table.rst index 2c36e676bb..04a03c5cf9 100755 --- a/docs/table.rst +++ b/docs/table.rst @@ -156,6 +156,10 @@ of commonly used methods. The full list can be found in the API section. * - Method - Description + * - :py:meth:`~parsons.etl.etl.ETL.head` + - Get the first n rows of a table + * - :py:meth:`~parsons.etl.etl.ETL.tail` + - Get the last n rows of a table * - :py:meth:`~parsons.etl.etl.ETL.add_column` - Add a column * - :py:meth:`~parsons.etl.etl.ETL.remove_column` diff --git a/test/test_etl.py b/test/test_etl.py index 244781d1e7..ad9359ec24 100644 --- a/test/test_etl.py +++ b/test/test_etl.py @@ -997,3 +997,15 @@ def test_deduplicate(self): tbl_expected = Table([["a", "b", "c"], [1, 2, 3], [1, 3, 2], [2, 3, 4]]) tbl.deduplicate(["a", "b"]) assert_matching_tables(tbl_expected, tbl) + + def test_head(self): + tbl = Table([["a", "b"], [1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) + tbl_expected = Table([["a", "b"], [1, 2], [3, 4]]) + tbl.head(2) + assert_matching_tables(tbl_expected, tbl) + + def test_tail(self): + tbl = Table([["a", "b"], [1, 2], [3, 4], [5, 6], [7, 8], [9, 10]]) + tbl_expected = Table([["a", "b"], [7, 8], [9, 10]]) + tbl.tail(2) + assert_matching_tables(tbl_expected, tbl) From 6a53137e7d5cf25d3c11aa67deb24d9767cdb825 Mon Sep 17 00:00:00 2001 From: matthewkrausse <106627640+mattkrausse@users.noreply.github.com> Date: Tue, 9 Jul 2024 15:15:04 -0600 Subject: [PATCH 3/5] feat: Add campaignId parameter to apply_responses method in People class --- parsons/ngpvan/people.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/parsons/ngpvan/people.py b/parsons/ngpvan/people.py index f8c5727f53..a95175bac4 100644 --- a/parsons/ngpvan/people.py +++ b/parsons/ngpvan/people.py @@ -586,6 +586,7 @@ def apply_response( result_code_id=None, omit_contact=False, phone=None, + campaignId=None, ): """ Apply responses such as survey questions, activist codes, and volunteer actions @@ -648,6 +649,7 @@ def apply_response( "inputTypeId": input_type_id, "dateCanvassed": date_canvassed, "omitActivistCodeContactHistory": omit_contact, + "campaignId": campaignId, }, "resultCodeId": result_code_id, } From 057e02772b71fca18e0450aee2393f99fdbae843 Mon Sep 17 00:00:00 2001 From: Matthew Krausse <69082853+matthewkrausse@users.noreply.github.com> Date: Tue, 9 Jul 2024 16:44:08 -0600 Subject: [PATCH 4/5] Update people.py added campaignId param to docstring --- parsons/ngpvan/people.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/parsons/ngpvan/people.py b/parsons/ngpvan/people.py index a95175bac4..7fd84c455b 100644 --- a/parsons/ngpvan/people.py +++ b/parsons/ngpvan/people.py @@ -622,6 +622,8 @@ def apply_response( attempts. phone: str `Optional`; Phone number of any type (Work, Cell, Home) + campaignId: int + `Optional`; a valid Campaign ID. `Returns:` ``True`` if successful From 90896850bc3ad188dd2178fd7f34bf58ea50dd10 Mon Sep 17 00:00:00 2001 From: matthewkrausse <106627640+mattkrausse@users.noreply.github.com> Date: Fri, 4 Oct 2024 17:03:18 -0500 Subject: [PATCH 5/5] Removes error flag when contact type phone and phone is not passed --- parsons/ngpvan/people.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/parsons/ngpvan/people.py b/parsons/ngpvan/people.py index 7fd84c455b..06e48c5aa7 100644 --- a/parsons/ngpvan/people.py +++ b/parsons/ngpvan/people.py @@ -656,22 +656,6 @@ def apply_response( "resultCodeId": result_code_id, } - if ( - contact_type_id == 1 # Phone - or contact_type_id == 19 # Auto Dial - or contact_type_id == 37 # SMS Text - or contact_type_id == 67 # Phone Bank - or contact_type_id == 68 # Consumer Phone - or contact_type_id == 72 # Leader Phone - or contact_type_id == 112 # Personal Phone - or contact_type_id == 132 # Relational Text - or contact_type_id == 143 # Distributed Text - or contact_type_id == 147 # Bulk Text - or contact_type_id == 149 # Paid SMS - ): - if not phone: - raise Exception("A phone number must be provided if canvassed via phone or SMS") - if phone: json["canvassContext"]["phone"] = { "dialingPrefix": "1",