Repository: HallLab/clarite-python

Issue:
`categorize` has trouble when attempting to classify a string variable as continuous
```AttributeError                            Traceback (most recent call last)
<ipython-input-65-5899bda027b5> in <module>
      1 # Automate categorization
----> 2 data = clarite.modify.categorize(data)
      3 
      4 # Set known categorizations
      5 # Continuous

/storage/work/j/jrm5100/python_venvs/venv_clarite/lib/python3.6/site-packages/clarite/internal/utilities.py in wrapped(*args, **kwargs)
     12         click.echo(f"Running {func.__name__}")
     13         click.echo("-" * 80)
---> 14         result = func(*args, **kwargs)
     15         click.echo("=" * 80)
     16         return result

/storage/work/j/jrm5100/python_venvs/venv_clarite/lib/python3.6/site-packages/clarite/modules/modify.py in categorize(data, cat_min, cat_max, cont_min)
    117                 keep_cont[col] = False
    118                 check_cont[col] = True
--> 119                 data[col] = data.loc[~col.isna(), col].astype(str)
    120 
    121     # Other - Convert non-NA values to string type

AttributeError: 'str' object has no attribute 'isna'
```

Discussion:

Patch:
diff --git a/clarite/modules/modify.py b/clarite/modules/modify.py
index 426ab86..879a5ff 100644
--- a/clarite/modules/modify.py
+++ b/clarite/modules/modify.py
@@ -116,7 +116,7 @@ def categorize(data: pd.DataFrame, cat_min: int = 3, cat_max: int = 6, cont_min:
                 # Couldn't convert to a number- possibly a categorical variable with string names?
                 keep_cont[col] = False
                 check_cont[col] = True
-                data[col] = data.loc[~col.isna(), col].astype(str)
+                data[col] = data.loc[:, col].astype(str)
 
     # Other - Convert non-NA values to string type
     check_other = ~empty_vars & ~keep_constant & ~keep_bin & ~keep_cat & ~check_cont & ~keep_cont


Test patch:
diff --git a/clarite/tests/modify/test_modify.py b/clarite/tests/modify/test_modify.py
index 2140df6..91b34d7 100644
--- a/clarite/tests/modify/test_modify.py
+++ b/clarite/tests/modify/test_modify.py
@@ -171,3 +171,18 @@ def test_transform(plantTraits, capfd):
     assert all(result['b'] == [2, 3, 4])
     assert all(result['c'] == [True, False, True])
     return
+
+
+def test_categorize_many_string():
+    """
+    Ensure an error isn't thrown when attempting to make a string column continuous
+    """
+    df = pd.DataFrame({
+        'a': range(100),
+        'b': range(100),
+        'c': [str(n)+"ABC" for n in range(100)]})
+    categorized = modify.categorize(df)
+    # Dtypes and data shouldn't have actually changed.  'c' will remain an 'unknown' type.
+    assert (categorized.dtypes == df.dtypes).all()
+    assert (categorized == df).all().all()
+    return