
    h(                     b   d Z ddlmZ ddlZddlZddlZddlZej                  j                  d       ddl
ZddlZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 d Z2d Z3d	 Z4d
 Z5d Z6d Z7d Z8e9dk(  r e8        yy)a  
self-contained to write legacy storage pickle files

To use this script. Create an environment where you want
generate pickles, say its for 0.20.3, with your pandas clone
in ~/pandas

. activate pandas_0.20.3
cd ~/pandas/pandas

$ python -m tests.io.generate_legacy_storage_files     tests/io/data/legacy_pickle/0.20.3/ pickle

This script generates a storage file for the current arch, system,
and python version
  pandas version: 0.20.3
  output dir    : pandas/pandas/tests/io/data/legacy_pickle/0.20.3/
  storage format: pickle
created pickle file: 0.20.3_x86_64_darwin_3.5.2.pickle

The idea here is you are using the *current* version of the
generate_legacy_storage_files with an *older* version of pandas to
generate a pickle file. We will then check this file into a current
branch, and test using test_pickle.py. This will load the *older*
pickles and test versus the current data that is generated
(with main). These are then compared.

If we have cases where we changed the signature (e.g. we renamed
offset -> freq in Timestamp). Then we have to conditionally execute
in the generate_legacy_storage_files.py to make it
run under the older AND the newer version.

    )	timedeltaN)Categorical	DataFrameIndex
MultiIndexNaTPeriod
RangeIndexSeries	Timestampbdate_range
date_rangeinterval_rangeperiod_rangetimedelta_range)SparseArray)FY5253BusinessDayBusinessHourCustomBusinessDay
DateOffsetDayEasterHourLastWeekOfMonthMinute
MonthBeginMonthEndQuarterBegin
QuarterEndSemiMonthBeginSemiMonthEndWeekWeekOfMonth	YearBeginYearEndc                      t         j                  } t        j                  dt         j                        }| |dd | |dd  t	        t        |d            }d|_        |S )	N   dtype      blockkindbseries)npnanarangefloat64r   r   name)r3   arrr1   s      RD:\jyotish\venv\Lib\site-packages\pandas/tests/io/generate_legacy_storage_files.py_create_sp_seriesr9   Z   sT    
&&C ))Bbjj
)CC"ICH[734GGLN    c                      t         j                  } t        j                  dt         j                        }| |dd | |dd  t	        dt        |            }t        t        |d	      |
      }d|_        |S )Nr(   r)   r+   r,   r-   1/1/2011periodsr.   r/   index	btsseries)	r2   r3   r4   r5   r   lenr   r   r6   )r3   r7   
date_indexr1   s       r8   _create_sp_tsseriesrD   g   sf    
&&C ))Bbjj
)CC"ICHZS:J[73:FGGLNr:   c                  &   t         j                  } | | | dddddddg
ddd| | | ddddg
t        j                  d      j                  t         j                        dddddd| | | | g
d	}t        d
d      }t        ||      j                  t              S )Nr                     
   ABCDr<   r=   r?   )	r2   r3   r4   astypeint64r   r   applyr   )r3   datadatess      r8   _create_sp_framerW   u   s    
&&C 3Q1aAq1AsCaAq1YYr]!!"((+Aq!QS#s3	D 
B/ET'--k::r:   c                     ddddt         j                  gg dg dt        dd	      dd
t        d      ddgd} t        d      t	        dd      d}t        t        j                  d            t        dd	      t        ddd      t        t        j                  dt         j                              t        t        j                  dt         j                              t        ddd      t        g dd      d}t        d      |d<   t        dd	      |d<   dt        j                  t        t!        g dg d g       d!d"g#      i}t#        | d$         t#        | d%         t#        | d&         t#        t        j                  d      j%                  t         j&                        t        dd	      '      t#        t        j                  d      j%                  t         j                        t        j                  t        t!        g d(g d)g       d*d+g#      '      t#        t        j                  d      j%                  t         j                        g d,'      t#        t)        g d-            t#        t        dd	            t#        t        ddd./            t#        t	        d0      gdz        t#        g dd      d1}t+        |       }t-        d2      |_        t+        |d3   |d3   d
z   d4      t+        |d5   |d5   d
z   d4      t+        d6D ci c]  }|| |   
 c}      t+        t        j                  d      j%                  t         j                        t        j                  d      j%                  t         j&                        d4t        j                  t        t!        g d7g d8g       d!d"g#      '      t+        t        j                  d9      j1                  dd:      j%                  t         j                        g d;<      t+        d$t)        dd=g      i      t+        t)        g d-      t        j                  d:      j%                  t         j&                        d4      |t+        t        d>d.?      t        d@dA?      d4t3        d      '      t+        t        d>d.?      t        d@dA?      t        d@dB?      dCt3        d      '      t+        t#        g dd      t#        g d8d      d4      dD}t)        t-        dE            t)        t        j                  dF            t)        t        j                  dG            dH}t        dI      t4        t        dId.?      dJ}	i dKt7        d
L      dMt7        dNdOP      dQt9        t;        dRS      T      dUt=        dVdNdWX      dYt?        dZ[      d\tA        dR]      d^tC        d_]      d`tE        d
      datG        d
      dbtI        d
      dctK        d
      ddtM        d
      detO        d
      dftQ        d
      dgtS        d
      dhtS        didjd
k      dltU        d:dmn      tW        d
d:o      tY        didNdpdqr      t[               t]        d
      t_        d
      ds}
|||||ta               tc               dtd3te               i||	|
du
S c c}w )vzcreate the pickle datag        g      ?g       @g      @)r   rF   r   rF   r   )foo1foo2foo3foo4foo5z1/1/2009rJ   r=   rF   20100101foo)rN   rO   rP   rQ   E201301012012M)	timestampperiodrL   z
2013-01-01)freqr>   r)   z00:00:0030min)r_   barbazquxquuxstring)intdatere   floatuintr   rl   ranger   intervalreg2)rh   rh   ri   ri   r_   r_   rj   rj   )onetwort   ru   rt   ru   rt   ru   firstsecond)namesrN   rO   r`   r?   )rF   rF   rG   rG   rG   )rH   rI   rH   rI   rJ   rt   ru   )rN   rO   rP   rQ   rN   )r_   rh   ri   z
US/Eastern)r>   tz2000Q1)ro   rm   mixedtsmidupcatdtdt_tzre   rl   ABCDAro   )rN   rO   rm   rM   )rh   rh   ri   ri   ri   )rt   ru   rt   ru   threer(   rH   )rN   rO   rN   )columnsrh   20130102)ry   20130603CETUTC)rN   rO   rP   )ro   rm   r{   r}   r~   
cat_onecolcat_and_float	mixed_dupdt_mixed_tzsdt_mixed2_tzsrl   abcdefgi  i'  )int8int16int32z
2011-01-01)normalnatry   r   )yearsDateOffset_h_nsrK   i  )hournanosecondsr   	   )seconds)offsetr   Tz15:14)	normalizenendr   zMon Fri)weekmaskr!   )day_of_monthr"      r   r   r   r    r   r%   r&   r#   	Week_TuesrG   F)r   weekdayr$   rI   )weekr   )r   r   r+   last)r   r   startingMonth	variation)r   r   r   r   r   )ro   r|   )
seriesframer@   scalarsr}   	sp_seriessp_framer   rd   offsets)3r2   r3   r   r   r	   r   r4   r   r5   uint64r   r
   r   r   from_tuplestuplezipr   rR   rS   r   r   listr   reshaperq   r   r   r   r   r   r   r!   r"   r   r   r   r    r   r%   r&   r#   r$   r   r   r   r   r   r9   rD   rW   )rU   r   r@   r}   r   mixed_dup_dfkr   r   rd   offs              r8   create_pickle_datar      s%    3S"&&)5
A.1i
+UC8D &j1VFC=PQG RYYr]#:r2|#rBryy2::67bii"))45$ZgrJ<HME  ^E'N&q"5E* 	
&&PP H%


B S	"d3i S	"IIbM  **ZQS2T
 IIaL

+((cO_=>?u~
 biil))"**5=VWk"789Z
A67
:q\JK&*+a/0=XN%F* T?L=Lvg7JKLve}6%=13DEF0DE0D1AtAwJ0DEF))A,%%bjj1		!8K8KBHH8UV((?A )

 IIbM!!!Q'..rzz:O
  k5%.&A BC" !67YYq\((2
 "!zl;ze4 (
 #zl;ze4ze4
 (
 @QAR
Y2Ej DO,RYYt_-RYYu-.C L)6Ijq):1$? 	{)A*>? 	tqgF	
 	.	B 	.a8 	"5 	jm 	HQK 	Q 	jm 	s1v 	Yq\ 	71: 	Q  	T!ua8!" 	{15#$ +Q:1aqFK(Q)-C4 02:M:OP.01 m Fs   [ c            	         dj                  t        t        j                        t        t	        j
                               t        t	        j                         j                               t        t	        j                               g      S )N_)	joinstrpandas__version__plmachinesystemlowerpython_version r:   r8   platform_namer   )  s\    88""#

		!!#$!!#$		
 r:   c                    t         j                  }t        d       t        d|        t        d|         t        d       t                d}t	        t
        j                  j                  | |      d      5 }t        j                  t               |t        j                         d d d        t        d|        y # 1 sw Y   xY w)NzUThis script generates a storage file for the current arch, system, and python versionz  pandas version: z  output dir    : z  storage format: picklez.picklewbzcreated pickle file: )r   r   printr   openospathr   pickledumpr   DEFAULT_PROTOCOL)
output_dirversionpthfhs       r8   write_legacy_picklesr   4  s      G		 
wi
()	zl
+,	
$%_W
%C	bggll:s+T	2b&("f.E.EF 
3 
!#
'( 
3	2s   :.B??Cc                     t         j                  j                  dd       dt        t         j                        cxk  rdk  sn t        j
                  d       t        t         j                  d         } t        t         j                  d         }t        j                  j                  |       st        j                  |        |dk(  rt        | 	       y t        j
                  d
       y )Nr    rH   rI   zhSpecify output directory and storage type: generate_legacy_storage_files.py <output_dir> <storage_type> rF   rG   r   )r   z&storage_type must be one of {'pickle'})sysr   insertrB   argvexitr   r   existsmkdirr   )r   storage_types     r8   write_legacy_filer   G  s    HHOOArCHH""<	

 SXXa[!Jsxx{#L77>>*%
x
39:r:   __main__):__doc__datetimer   r   r   platformr   r   r   popnumpyr2   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   pandas.arraysr   pandas.tseries.offsetsr   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r9   rD   rW   r   r   r   r   __name__r   r:   r8   <module>r      s    D  	   
 Q       &     0
;cL)&;, z r:   