Repository: alteryx/woodwork (python)

Issue:
Add input validation to ww.init_series
The `init_series` function added as part of the accessor update does not validate that the input passed in for the series is a valid series type. If the user passes in a non-series object an error is currently raised, but the error message is not helpful in understanding what went wrong.  Current behavior:
```python
>>> ww.init_series(3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/nate.parsons/dev/woodwork/woodwork/accessor_utils.py", line 38, in init_series
    logical_type = _get_column_logical_type(series, logical_type, series.name)
AttributeError: 'int' object has no attribute 'name'
```

We should add a validation check to this function and raise a better error if improper inputs are supplied.

Pull request description:
Add input validation to init_series to raise a better error
- Fixes #631 

Patch:
diff --git a/docs/source/release_notes.rst b/docs/source/release_notes.rst
index fdeb782..941ace5 100644
--- a/docs/source/release_notes.rst
+++ b/docs/source/release_notes.rst
@@ -2,11 +2,11 @@
 
 Release Notes
 -------------
-
 Future Release
 ==============
     * Enhancements
     * Fixes
+        * Add input validation to ww.init_series (:pr:`1015`)
     * Changes
         * Remove lines in ``LogicalType.transform`` that raise error if dtype conflicts (:pr:`1012`)
         * Add ``infer_datetime_format`` param to speed up ``to_datetime`` calls (:pr:`1016`)
@@ -14,7 +14,7 @@ Future Release
     * Testing Changes
 
     Thanks to the following people for contributing to this release:
-    :user:`tamargrey`, :user:`thehomebrewnerd`
+    :user:`simha104`, :user:`tamargrey`, :user:`thehomebrewnerd`
 
 
 v0.4.2 Jun 23, 2021
diff --git a/woodwork/accessor_utils.py b/woodwork/accessor_utils.py
index 469cb58..a0de1ad 100644
--- a/woodwork/accessor_utils.py
+++ b/woodwork/accessor_utils.py
@@ -30,8 +30,9 @@ def init_series(series, logical_type=None, semantic_tags=None,
     Returns:
         Series: A series with Woodwork typing information initialized
     """
+    if not _is_series(series):
+        raise TypeError(f'Input must be of series type. The current input is of type {type(series)}')
     logical_type = _get_column_logical_type(series, logical_type, series.name)
-
     new_series = logical_type.transform(series)
     new_series.ww.init(logical_type=logical_type,
                        semantic_tags=semantic_tags,


Test patch:
diff --git a/woodwork/tests/utils/test_accessor_utils.py b/woodwork/tests/utils/test_accessor_utils.py
index 03df5b4..436487e 100644
--- a/woodwork/tests/utils/test_accessor_utils.py
+++ b/woodwork/tests/utils/test_accessor_utils.py
@@ -37,6 +37,14 @@ def test_init_series_valid_conversion_specified_ltype(sample_series):
     assert series.ww.semantic_tags == set()
 
 
+def test_init_series_with_invalid_type(sample_df):
+    inputs = [sample_df, 1, "string", None]
+    for input_ in inputs:
+        error_message = f'Input must be of series type. The current input is of type {type(input_)}'
+        with pytest.raises(TypeError, match=error_message):
+            init_series(input_)
+
+
 def test_init_series_valid_conversion_inferred_ltype(sample_series):
     if ks and isinstance(sample_series, ks.Series):
         sample_series = sample_series.astype('str')