Repository: pandas-dev/pandas

Issue:
BUG: invalid constrution of a Series with dtype=str
```python
pd.Series('', dtype=str, index=range(1000))
```

throws a `ValueError` with the following message:

```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\james\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\series.py", line 266, in __init__
    data = SingleBlockManager(data, index, fastpath=True)
  File "C:\Users\james\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\internals.py", line 4402, in __init__
    fastpath=True)
  File "C:\Users\james\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\internals.py", line 2957, in make_block
    return klass(values, ndim=ndim, fastpath=fastpath, placement=placement)
  File "C:\Users\james\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\internals.py", line 2082, in __init__
    placement=placement, **kwargs)
  File "C:\Users\james\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\internals.py", line 111, in __init__
    raise ValueError('Wrong number of dimensions')
ValueError: Wrong number of dimensions
```

Would it be possible to fix the behavior to initialize the series to `''` (or at least provide a clearer message)?


Discussion:
``pd.Series('', dtype=object, index=range(1000))``
That's ok. String uses 'object' dtype.
this takes a different path in master. We pretty much treat str as object. So this is a construction bug.
```
In [4]: pd.Series('',  index=range(1000), dtype=str)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-3bd08f17c610> in <module>()
----> 1 pd.Series('',  index=range(1000), dtype=str)

~/pandas/pandas/core/series.py in __init__(self, data, index, dtype, name, copy, fastpath)
    237             else:
    238                 data = _sanitize_array(data, index, dtype, copy,
--> 239                                        raise_cast_failure=True)
    240 
    241                 data = SingleBlockManager(data, index, fastpath=True)

~/pandas/pandas/core/series.py in _sanitize_array(data, index, dtype, copy, raise_cast_failure)
   3260         # GH 16605
   3261         # If not empty convert the data to dtype
-> 3262         if not isna(data).all():
   3263             data = np.array(data, dtype=dtype, copy=False)
   3264 

AttributeError: 'bool' object has no attribute 'all'

```

@jamesqo there is no reason to specify a dtype here as this will be inferred to ``object`` dtype anyhow (``str`` as I said above is pretty much an alias for ``object`` dtype).

a PR to fix is welcome.
@jamesqo note that setting the string ``''`` like this doesn't have much utilitiy. pandas has a full suite of string operations that are all NaN aware.

Resolving patch:
diff --git a/pandas/core/series.py b/pandas/core/series.py
--- a/pandas/core/series.py
+++ b/pandas/core/series.py
@@ -4059,9 +4059,10 @@ def _try_cast(arr, take_fast_path):
     if issubclass(subarr.dtype.type, compat.string_types):
         # GH 16605
         # If not empty convert the data to dtype
-        if not isna(data).all():
-            data = np.array(data, dtype=dtype, copy=False)
-
-        subarr = np.array(data, dtype=object, copy=copy)
+        # GH 19853: If data is a scalar, subarr has already the result
+        if not is_scalar(data):
+            if not np.all(isna(data)):
+                data = np.array(data, dtype=dtype, copy=False)
+            subarr = np.array(data, dtype=object, copy=copy)
 
     return subarr


Test patch:
diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py
--- a/pandas/tests/series/test_constructors.py
+++ b/pandas/tests/series/test_constructors.py
@@ -110,6 +110,11 @@ def test_constructor_empty(self, input_class):
             empty2 = Series(input_class(), index=lrange(10), dtype='float64')
             assert_series_equal(empty, empty2)
 
+            # GH 19853 : with empty string, index and dtype str
+            empty = Series('', dtype=str, index=range(3))
+            empty2 = Series('', index=range(3))
+            assert_series_equal(empty, empty2)
+
     @pytest.mark.parametrize('input_arg', [np.nan, float('nan')])
     def test_constructor_nan(self, input_arg):
         empty = Series(dtype='float64', index=lrange(10))