Repository: brandonschabell/datetransform

Issue:
Make "inplace" optional
Currently the dataframe is edited inplace. Make this an optional argument that defaults to False so a copy of the dataframe is updated.

Discussion:

Patch:
diff --git a/.travis.yml b/.travis.yml
index 83d257a..5cbb4fb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,7 +14,7 @@ before_install:
   - pip install pytest-cov
 
 install:
-  - pip install -e .
+  - pip install -e .[tests]
 
 script:
   - pytest --cov-report=xml --cov=datetransform tests/
diff --git a/datetransform/transform.py b/datetransform/transform.py
index fd7c8cf..5ecbb04 100644
--- a/datetransform/transform.py
+++ b/datetransform/transform.py
@@ -1,7 +1,9 @@
 import numpy as np
 import pandas as pd
 
-def add_date_features(df: pd.DataFrame, date_field_name: str, time=True):
+def add_date_features(df: pd.DataFrame, date_field_name: str, time=True, inplace=False):
+    if not inplace:
+        df = df.copy()
     make_date(df, date_field_name)
     field = df[date_field_name]
     attr = ['Year', 'Month', 'Week', 'Day', 'DayOfWeek', 'DayOfYear', 'Is_Month_End', 'Is_Month_Start',
diff --git a/setup.py b/setup.py
index 8d60e55..8696544 100644
--- a/setup.py
+++ b/setup.py
@@ -8,15 +8,15 @@ with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
 
 
 test_requirements = [
-    'pytest'
+    'pytest>=5.4.1'
 ]
 
 setup(
     name='datetransform',
-    version='0.1.1',
+    version='0.2.0',
     packages=find_packages(),
     url='https://www.github.com/brandonschabell/datetransform',
-    download_url='https://github.com/brandonschabell/datetransform/archive/v0.1.1.tar.gz',
+    download_url='https://github.com/brandonschabell/datetransform/archive/v0.2.0.tar.gz',
     license='MIT',
     author='Brandon Schabell',
     author_email='brandonschabell@gmail.com',


Test patch:
diff --git a/tests/test_transform.py b/tests/test_transform.py
index d70f7b0..4fc4620 100644
--- a/tests/test_transform.py
+++ b/tests/test_transform.py
@@ -4,7 +4,6 @@ from datetransform import transform
 
 
 def test_add_date_features():
-
     df = pd.DataFrame({'dateCol': ['2019-08-09 16:39:47']})
     df = transform.add_date_features(df, 'dateCol')
     assert df.columns.tolist() == ['dateCol',
@@ -23,3 +22,30 @@ def test_add_date_features():
                                    'dateColHour',
                                    'dateColMinute',
                                    'dateColSecond']
+
+
+def test_inplace_transform():
+    df = pd.DataFrame({'dateCol': ['2019-08-09 16:39:47']})
+    transform.add_date_features(df, 'dateCol', inplace=True)
+    assert df.columns.tolist() == ['dateCol',
+                                   'dateColYear',
+                                   'dateColMonth',
+                                   'dateColWeek',
+                                   'dateColDay',
+                                   'dateColDayOfWeek',
+                                   'dateColDayOfYear',
+                                   'dateColIsMonthEnd',
+                                   'dateColIsMonthStart',
+                                   'dateColIsQuarterEnd',
+                                   'dateColIsQuarterStart',
+                                   'dateColIsYearEnd',
+                                   'dateColIsYearStart',
+                                   'dateColHour',
+                                   'dateColMinute',
+                                   'dateColSecond']
+
+
+def test_not_inplace_transform():
+    df = pd.DataFrame({'dateCol': ['2019-08-09 16:39:47']})
+    transform.add_date_features(df, 'dateCol')
+    assert df.columns.tolist() == ['dateCol']
\ No newline at end of file