Repository: pandas-dev/pandas

Issue:
pd.to_pickle() and pd.read_pickle() bug?
I'm on windows 7, anaconda, python 2.7.9, 32bit
pandas 0.16.2

try this:

``` python
import pandas as pd
df4 = pd.DataFrame(index=P.date_range('1750-1-1', '2050-1-1', freq='7D')
pd.to_pickle(df4, '7d.test')
pd.read_pickle('7d.test')


In [84]: P.read_pickle('7d.test')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-84-0108eecfbea7> in <module>()
----> 1 P.read_pickle('7d.test')

C:\Users\LV\Miniconda\lib\site-packages\pandas\io\pickle.pyc in read_pickle(path)
     58 
     59     try:
---> 60         return try_read(path)
     61     except:
     62         if PY3:

C:\Users\LV\Miniconda\lib\site-packages\pandas\io\pickle.pyc in try_read(path, encoding)
     55             except:
     56                 with open(path, 'rb') as fh:
---> 57                     return pc.load(fh, encoding=encoding, compat=True)
     58 
     59     try:

C:\Users\LV\Miniconda\lib\site-packages\pandas\compat\pickle_compat.pyc in load(fh, encoding, compat, is_verbose)
    114         up.is_verbose = is_verbose
    115 
--> 116         return up.load()
    117     except:
    118         raise

C:\Users\LV\Miniconda\lib\pickle.pyc in load(self)
    856             while 1:
    857                 key = read(1)
--> 858                 dispatch[key](self)
    859         except _Stop, stopinst:
    860             return stopinst.value

C:\Users\LV\Miniconda\lib\site-packages\pandas\compat\pickle_compat.pyc in load_reduce(self)
     18 
     19     try:
---> 20         stack[-1] = func(*args)
     21         return
     22     except Exception as e:

C:\Users\LV\Miniconda\lib\site-packages\pandas\tseries\index.pyc in _new_DatetimeIndex(cls, d)
    113     # data are already in UTC
    114     tz = d.pop('tz',None)
--> 115     result = cls.__new__(cls, **d)
    116     result.tz = tz
    117     return result

C:\Users\LV\Miniconda\lib\site-packages\pandas\util\decorators.pyc in wrapper(*args, **kwargs)
     86                 else:
     87                     kwargs[new_arg_name] = new_arg_value
---> 88             return func(*args, **kwargs)
     89         return wrapper
     90     return _deprecate_kwarg

C:\Users\LV\Miniconda\lib\site-packages\pandas\tseries\index.pyc in __new__(cls, data, freq, start, end, periods, copy, name, tz, verify_integrity, normalize, closed, ambiguous, **kwargs)
    334                     if not np.array_equal(subarr.asi8, on_freq.asi8):
    335                         raise ValueError('Inferred frequency {0} from passed dates does not'
--> 336                                          'conform to passed frequency {1}'.format(inferred, freq.freqstr))
    337 
    338         if freq_infer:

ValueError: Inferred frequency W-THU from passed dates does notconform to passed frequency 7D

```



Discussion:

Resolving patch:
diff --git a/pandas/tseries/index.py b/pandas/tseries/index.py
--- a/pandas/tseries/index.py
+++ b/pandas/tseries/index.py
@@ -120,7 +120,8 @@ def _new_DatetimeIndex(cls, d):
     # data are already in UTC
     # so need to localize
     tz = d.pop('tz',None)
-    result = cls.__new__(cls, **d)
+
+    result = cls.__new__(cls, verify_integrity=False, **d)
     if tz is not None:
         result = result.tz_localize('UTC').tz_convert(tz)
     return result


Test patch:
diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py
--- a/pandas/tseries/tests/test_timeseries.py
+++ b/pandas/tseries/tests/test_timeseries.py
@@ -2142,8 +2142,8 @@ def test_period_resample_with_local_timezone_dateutil(self):
 
 
     def test_pickle(self):
-        #GH4606
 
+        # GH4606
         p = self.round_trip_pickle(NaT)
         self.assertTrue(p is NaT)
 
@@ -2153,6 +2153,11 @@ def test_pickle(self):
         self.assertTrue(idx_p[1] is NaT)
         self.assertTrue(idx_p[2] == idx[2])
 
+        # GH11002
+        # don't infer freq
+        idx = date_range('1750-1-1', '2050-1-1', freq='7D')
+        idx_p = self.round_trip_pickle(idx)
+        tm.assert_index_equal(idx, idx_p)
 
 def _simple_ts(start, end, freq='D'):
     rng = date_range(start, end, freq=freq)