Repository: pandas-dev/pandas

Issue:
COMPAT: recent numpy deprecation warnings
getting lots of deprecation warnings from numpy.

```
(pandas) bash-3.2$ pytest pandas/tests/test_resample.py pandas/tests/io/json/test_json_table_schema.py 
============================================================================================================ test session starts ============================================================================================================
platform darwin -- Python 3.6.3, pytest-3.3.0, py-1.5.2, pluggy-0.6.0
rootdir: /Users/jreback/pandas, inifile: setup.cfg
plugins: xdist-1.20.1, forked-0.2, cov-2.5.1, hypothesis-3.38.5
collected 350 items                                                                                                                                                                                                                         

pandas/tests/test_resample.py ...................................................................................................................ssss................................................................................ [ 56%]
...............................ssss..................................                                                                                                                                                                 [ 76%]
pandas/tests/io/json/test_json_table_schema.py ...................................................x..x..x..x..xxxx..x..x..X..X...                                                                                                     [100%]

============================================================================================================= warnings summary ==============================================================================================================
pandas/tests/io/json/test_json_table_schema.py::TestTableOrientReader::()::test_read_json_table_orient[vals2-None]
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)

pandas/tests/io/json/test_json_table_schema.py::TestTableOrientReader::()::test_read_json_table_orient[vals2-idx]
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)

pandas/tests/io/json/test_json_table_schema.py::TestTableOrientReader::()::test_read_json_table_orient[vals2-index]
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)

pandas/tests/io/json/test_json_table_schema.py::TestTableOrientReader::()::test_comprehensive
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)
  /Users/jreback/pandas/pandas/core/dtypes/cast.py:706: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
    return arr.astype(dtype)

-- Docs: http://doc.pytest.org/en/latest/warnings.html
================================================================================ 330 passed, 8 skipped, 10 xfailed, 2 xpassed, 16 warnings in 12.85 seconds =================================================================================
```


```
In [1]: arr = np.array(['2016-01-01T00:00:00.000Z', '2016-01-02T00:00:00.000Z',
   ...:        '2016-01-03T00:00:00.000Z', '2016-01-04T00:00:00.000Z'], dtype=object)
   ...: 

In [2]: arr.astype('<M8[ns]')
/Users/jreback/miniconda3/envs/pandas/bin/ipython:1: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future
  #!/Users/jreback/miniconda3/envs/pandas/bin/python
Out[2]: 
array(['2016-01-01T00:00:00.000000000', '2016-01-02T00:00:00.000000000',
       '2016-01-03T00:00:00.000000000', '2016-01-04T00:00:00.000000000'], dtype='datetime64[ns]')
```

I haven't seen these before, so a recent change must have triggered


Discussion:
cc @jbrockmendel cc @jschendel cc @WillAyd 
  
Just ran on upstream/master and did not get any warnings - are we running the same version?

**pd.show_versions()**
<details>

INSTALLED VERSIONS
------------------
commit: 16d02621212cd7d83f89533265fc039df1d7be10
python: 3.6.3.final.0
python-bits: 64
OS: Darwin
OS-release: 17.3.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.23.0.dev0+79.g16d026212
pytest: 3.2.1
pip: 9.0.1
setuptools: 36.5.0.post20170921
Cython: 0.26.1
numpy: 1.13.3
scipy: 1.0.0
pyarrow: 0.8.0
xarray: 0.10.0
IPython: 6.2.1
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: 0.4.0
matplotlib: 2.1.1
openpyxl: 2.5.0b1
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 1.0.2
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.1.13
pymysql: 0.7.11.None
psycopg2: None
jinja2: 2.10
s3fs: 0.1.2
fastparquet: 0.1.3
pandas_gbq: None
pandas_datareader: None

</details>
export PANDAS_TESTING_MODE=deprecate
first ; DeprecationWarnings are normally suppressed
we enable them in CI
Hmm OK. It appears the line

```python
pd.date_range('2016-01-01', freq='d', periods=4)
```

Is triggering this within the tests. Not immediately apparent to me why that would be the case but will take a look
So it looks like ``write_json`` is outputting the date range in the format that you provided above. Are we on the same page that we would have to change that behavior to support this?

This is without digging into the json code, but I suspect rather than changing the output format, we should instead replace uses of numpy conversion `.astype(<datetime>)` with our internal parser `pd.to_datetime(...)`
Odd how this is case, since I think that warning was created partially in response to `pandas`:

https://github.com/numpy/numpy/blob/2bacec9ecb0fc665117a22027b73812509a99f56/doc/release/1.11.0-notes.rst#compatibility-notes

Resolving patch:
diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py
--- a/pandas/core/dtypes/cast.py
+++ b/pandas/core/dtypes/cast.py
@@ -690,7 +690,7 @@ def astype_nansafe(arr, dtype, copy=True):
             raise ValueError('Cannot convert non-finite values (NA or inf) to '
                              'integer')
 
-    elif arr.dtype == np.object_ and np.issubdtype(dtype.type, np.integer):
+    elif is_object_dtype(arr.dtype) and np.issubdtype(dtype.type, np.integer):
         # work around NumPy brokenness, #1987
         return lib.astype_intsafe(arr.ravel(), dtype).reshape(arr.shape)
 
@@ -703,6 +703,19 @@ def astype_nansafe(arr, dtype, copy=True):
         dtype = np.dtype(dtype.name + "[ns]")
 
     if copy:
+
+        if arr.dtype == dtype:
+            return arr.copy()
+
+        # we handle datetimelikes with pandas machinery
+        # to be robust to the input type
+        elif is_datetime64_dtype(dtype):
+            from pandas import to_datetime
+            return to_datetime(arr).values
+        elif is_timedelta64_dtype(dtype):
+            from pandas import to_timedelta
+            return to_timedelta(arr).values
+
         return arr.astype(dtype)
     return arr.view(dtype)
 


Test patch:
diff --git a/pandas/tests/io/json/test_json_table_schema.py b/pandas/tests/io/json/test_json_table_schema.py
--- a/pandas/tests/io/json/test_json_table_schema.py
+++ b/pandas/tests/io/json/test_json_table_schema.py
@@ -499,7 +499,7 @@ def test_read_json_table_orient(self, index_nm, vals):
         tm.assert_frame_equal(df, result)
 
     @pytest.mark.parametrize("index_nm", [
-        None, "idx", pytest.param("index", marks=pytest.mark.xfail)])
+        None, "idx", "index"])
     @pytest.mark.parametrize("vals", [
         {'timedeltas': pd.timedelta_range('1H', periods=4, freq='T')},
         {'timezones': pd.date_range('2016-01-01', freq='d', periods=4,