ENH: support for nanosecond time in offset and period
State: closed

closes #1812

This pull request fixes handling of nanosecond times in periods and offsets. In addition it simplifies the internal processing of intraday periods.

``` python
In []: pd.date_range('2013-01-01', periods=5, freq=pd.offsets.Nano(5))
Out[]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-01-01 00:00:00, ..., 2013-01-01 00:00:00.000000020]
Length: 5, Freq: 5N, Timezone: None
```

It requires Numpy 1.7 to work, using Numpy 1.6 yields the original behaviour before this PR.

This is the continuation of #2555 after it was merged without effect fixing issue #1812.

The biggest part is a refactoring of pandas/src/period.c to use a conversion factor matrix for intraday conversion. This minimizes the impact of adding three more intraday time units (ms, us and ns). Thus the amount of frequency conversion methods is reduced to one per intraday frequency source or target. The intraday conversion factor is looked up in the conversion factor matrix inside the method.

Nanosecond support is only available when using numpy >= 1.7. When using with numpy < 1.7 everything except nanosecond support should work as expected.


Labels:
name: Enhancement
name: Datetime
description: Datetime data dtype
name: Dtype Conversions
description: Unexpected or buggy dtype conversions

Comments:
ypu have some failnig tests.....I think you need to Skip by `raise nose.SkipTest`,
not `self.SkipTest`

thanks for the hint, the tests are green again

@wesm take a look?

I'll have a look soon as I can and we can merge for 0.11

fwiw, I suggest putting this off to 0.12, it's already seen some subtle breakage and it should
get a period of beta testing in master before shipping in a release IMO.
No reflection on the code, just prudence.

I agree, it may be better to have a longer period of testing.

OK let's merge right after 0.11. We'll want to have a 0.11.x maintenance branch in case we need to fix any critical bugs in 0.11.1/2/...

There's a slew of stuff for "right after 0.11", it looks like we're naturally moving towards a 
"merge window" model for releases.

@wuan, any last minute tweaks before we go live in master?

No, not at the moment. I will have a look at #3375 now.

you rebased on top of master?

can u also post a perf check?

eg

test_perf -b before_commit -t last_commit

anything say > 15% diff

This is a current perofmance check, there is quite a distribution of times:

```
-------------------------------------------------------------------------------
Test name                                    | head[ms] | base[ms] |  ratio   |
-------------------------------------------------------------------------------
dataframe_reindex                            |   0.3353 |   0.4524 |   0.7412 |
panel_from_dict_equiv_indexes                |  22.9453 |  29.8474 |   0.7688 |
reindex_daterange_backfill                   |   0.1794 |   0.2103 |   0.8530 |
series_drop_duplicates_string                |   0.3813 |   0.4307 |   0.8852 |
append_frame_single_homogenous               |   0.1747 |   0.1964 |   0.8895 |

 ...

timeseries_asof_single                       |   0.0357 |   0.0246 |   1.4484 |
frame_xs_col                                 |   0.0226 |   0.0153 |   1.4767 |
reindex_fillna_backfill_float32              |   0.0796 |   0.0521 |   1.5298 |
timeseries_period_downsample_mean            |  17.5680 |  11.3323 |   1.5503 |
dti_reset_index                              |   0.1311 |   0.0533 |   2.4575 |
-------------------------------------------------------------------------------
Test name                                    | head[ms] | base[ms] |  ratio   |
-------------------------------------------------------------------------------
```

as times are more often wrapped with Timestamp, there is a performance impact. I can have a further look into this.

performance is tricky - some times multiple runs will give diff results

so obviously we care about biggest ratios 

do a %prun -l func()

in ipython to profile - I usually do on master then on my pr to see what the hotspots
often times its something simple to bring it down

it would be great to have this in 0.13 ... i've just pulled down and i'm going to do a little smoke testing

@wuan any thoughts? it's been a while... just want to bump this

Thanks for restarting activity ...

At the moment I'm investigating some broken tests due to features introduced in the meantime. I will have some more time mid of august to help bringing things forward.

Benchmark tests results are very strange at the moment, as some of the tests show speed differences, but do not involve new code at all. Still looking into this topic as well.

Pulled master and rebased.

There are still problems with strata._datetime_to_stata_elapsed raising a ValueError when there is a np.datetime64 instead of a datetime.datetime object. For me, this seems to be a bug in the strata code. Any thoughts?

do you have an example where I can reproduce this? 

It appears (bried glance), that the stata code iterrows over the frame; IF there is not a homogenous (e.g. all dates) data then I think the np.datetime64 will be coerced to datetime.datetime.

Agreed that this is a 'bug', or a at least a bad assumption.

Oops, the real problem was cause by a type cast bug introduced with this pull request which is finally gone now. Tests are green again.

At least there is now an open issue #4558 regarding export of np.datetime64 based types in index.

What happens on numpy < 1.7, `Nano` is just not available? or does it raise if I try to index by a nano on an index? (either is ok, just checking)....

There are 2 travis version (the 2.6 and 3.2) that run with numpy 1.6.1, so you can put in a specific test for this, see first item here: https://github.com/pydata/pandas/wiki/Tips-&-Tricks (you could even do something in the code too); there will very shortl be a variable in `core/common.py` which indicates this, see here: https://github.com/pydata/pandas/pull/4534 (as timedeltas64 are very buggy in < 1.7)

Nano existed well before this pull request and issue #1812. It just did not work, the effective period was zero.
Should we really introduce code to raise or only a kind of warning message, that numpy >= 1.7 is required to use Nano et. al.?

@wuan 

this PR adds the ability to _index_ by nanos, correct? (e.g. more than just representing)
them....

can you add an example to the top of the PR?

(this is with current master)

```
In [2]: s = Series([Timestamp('20130101 09:01:02')])

In [6]: s+pd.offsets.Milli(5)+pd.offsets.Micro(6)+pd.offsets.Nano(7)
Out[6]: 
0   2013-01-01 09:01:02.005006007
dtype: datetime64[ns]
```

What does it do in < 1.7? (can you give an example?)

@wuan can you rerun the perf impact?

Here is the current performance comparison. I will have a look in the slow operations in the next days.

```
-------------------------------------------------------------------------------
Test name                                    | head[ms] | base[ms] |  ratio   |
-------------------------------------------------------------------------------
join_dataframe_index_single_key_small        |   8.0736 |   9.6220 |   0.8391 |
match_strings                                |   0.4493 |   0.4973 |   0.9035 |
mask_bools                                   |  57.3673 |  62.3620 |   0.9199 |
frame_repr_tall                              |   3.8280 |   4.1060 |   0.9323 |
groupby_frame_apply_overhead                 |  10.1500 |  10.8813 |   0.9328 |
read_csv_comment2                            |  29.1837 |  31.2207 |   0.9348 |
groupby_sum_booleans                         |   1.4513 |   1.5481 |   0.9375 |
datetimeindex_unique                         |   0.1737 |   0.1846 |   0.9410 |
indexing_dataframe_boolean_no_ne             |  78.3010 |  83.1940 |   0.9412 |
frame_iteritems_cached                       |   0.8077 |   0.8574 |   0.9421 |
dti_reset_index_tz                           |  16.7147 |  17.7270 |   0.9429 |
reindex_fillna_backfill                      |   0.9066 |   0.9583 |   0.9461 |
groupbym_frame_apply                         |  52.6273 |  55.5476 |   0.9474 |
lib_fast_zip_fillna                          |  18.3074 |  19.2664 |   0.9502 |
timeseries_asof_single                       |   0.0447 |   0.0470 |   0.9509 |

...

stat_ops_level_frame_sum                     |   5.1893 |   4.9037 |   1.0582 |
indexing_dataframe_boolean_rows_object       |   0.7664 |   0.7223 |   1.0610 |
frame_reindex_upcast                         |  20.6413 |  19.4256 |   1.0626 |
frame_fancy_lookup                           |   5.1223 |   4.8033 |   1.0664 |
frame_to_csv2                                | 159.7477 | 149.5946 |   1.0679 |
groupby_last                                 |   6.4550 |   6.0356 |   1.0695 |
frame_loc_dups                               |   1.1450 |   1.0684 |   1.0718 |
frame_mult                                   |   8.0183 |   7.4713 |   1.0732 |
indexing_dataframe_boolean_st                | 106.0576 |  95.9617 |   1.1052 |
frame_constructor_ndarray                    |   0.0697 |   0.0630 |   1.1059 |
timeseries_period_downsample_mean            |  22.1117 |   9.4171 |   2.3480 |
-------------------------------------------------------------------------------
Test name                                    | head[ms] | base[ms] |  ratio   |
-------------------------------------------------------------------------------
```

@wuan any remaining issues in this? quick perf check ?

pls rebase as well

I know this has been a long time ...but can get merged soon

I'm +1 on this as well

PR branch is now rebased.

Perf check results are:

```
-------------------------------------------------------------------------------
Test name                                    | head[ms] | base[ms] |  ratio   |
-------------------------------------------------------------------------------
frame_reindex_both_axes_ix                   |  33.0857 |  82.7637 |   0.3998 |
timeseries_asof_single                       |   0.0443 |   0.0621 |   0.7132 |
series_drop_duplicates_int                   |   0.9853 |   1.2160 |   0.8103 |
frame_add_st                                 |   7.2784 |   8.6757 |   0.8389 |
mask_bools                                   |  48.6004 |  57.5733 |   0.8441 |
indexing_dataframe_boolean                   |  79.0334 |  91.9917 |   0.8591 |
frame_ctor_list_of_dict                      | 113.4393 | 131.2003 |   0.8646 |
frame_constructor_ndarray                    |   0.0637 |   0.0733 |   0.8688 |
frame_repr_wide                              |   1.2666 |   1.4440 |   0.8772 |

...

stats_rank_average                           |  43.1611 |  41.9670 |   1.0285 |
indexing_panel_subset                        |   0.7000 |   0.6780 |   1.0325 |
timeseries_large_lookup_value                |   0.0397 |   0.0384 |   1.0331 |
reindex_frame_level_align                    |   1.1640 |   1.1247 |   1.0350 |
read_table_multiple_date_baseline            | 154.5357 | 149.0800 |   1.0366 |
stat_ops_frame_sum_int_axis_1                |   8.2783 |   7.9816 |   1.0372 |
write_csv_standard                           |  59.5917 |  57.4307 |   1.0376 |
join_dataframe_index_single_key_bigger       |   8.9626 |   8.6230 |   1.0394 |
frame_sort_index_by_columns                  |  53.3194 |  51.2873 |   1.0396 |
frame_drop_duplicates_na                     |  25.0137 |  24.0363 |   1.0407 |
datetimeindex_unique                         |   0.1984 |   0.1897 |   1.0457 |
lib_fast_zip                                 |  13.5216 |  12.7780 |   1.0582 |
sort_level_one                               |   6.9431 |   6.4450 |   1.0773 |
sort_level_zero                              |   7.1684 |   6.4646 |   1.1089 |
eval_frame_mult_python_one_thread            |  26.4789 |  23.8403 |   1.1107 |
timeseries_period_downsample_mean            |  22.4963 |   9.9820 |   2.2537 |
-------------------------------------------------------------------------------
Test name                                    | head[ms] | base[ms] |  ratio   |
-------------------------------------------------------------------------------
```

I took a closer look and profiled code analog to the timeseries_period_downsample_mean testcase

``` python
from pandas import date_range, Series, period_range
import numpy as np

N = 10000000

rng = date_range('1/1/2000', periods=N, freq='min')

if hasattr(Series, 'convert'):
    Series.resample = Series.convert

rng = period_range('1/1/2000', '1/1/2001', freq='T')
ts = Series(np.random.randn(len(rng)), index=rng)

ts.resample('D', how='mean')
```

but there was no significant difference between my changes and the current master (test took 1.270 seconds on master and 1.274 seconds on nanosecond_time). I have no clue where the factor of two above comes from.

@wuan wont' compile on windows (amd64), can you give a look see ?

```
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Ipandas/src/klib -Ipandas/src -IC:\python27\lib\site-packages\numpy\core\include -IC:\python27\include -IC:\p
thon27\PC /Tcpandas/src/datetime/np_datetime_strings.c /Fobuild\temp.win-amd64-2.7\Release\pandas/src/datetime/np_datetime_strings.obj
np_datetime_strings.c
c:\python27\lib\site-packages\numpy\core\include\numpy\npy_deprecated_api.h(8) : Warning Msg: Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
pandas/src/datetime/np_datetime_strings.c(224) : warning C4244: '=' : conversion from 'NPY_TIME_T' to 'int', possible loss of data
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Ipandas/src/klib -Ipandas/src -IC:\python27\lib\site-packages\numpy\core\include -IC:\python27\include -IC:\p
thon27\PC /Tcpandas/src/period.c /Fobuild\temp.win-amd64-2.7\Release\pandas/src/period.obj
period.c
c:\python27\lib\site-packages\numpy\core\include\numpy\npy_deprecated_api.h(8) : Warning Msg: Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
pandas/src/period.c(86) : warning C4244: 'return' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(88) : warning C4244: 'return' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(92) : warning C4244: 'return' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(94) : warning C4244: 'return' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(226) : warning C4244: '=' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(237) : warning C4244: '=' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(288) : error C2054: expected '(' to follow 'inline'
pandas/src/period.c(288) : error C2059: syntax error : 'type'
pandas/src/period.c(292) : error C2054: expected '(' to follow 'inline'
pandas/src/period.c(292) : error C2059: syntax error : 'type'
pandas/src/period.c(319) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(320) : error C2065: 'row_index' : undeclared identifier
pandas/src/period.c(320) : error C2065: 'row_index' : undeclared identifier
pandas/src/period.c(320) : error C2065: 'row_index' : undeclared identifier
pandas/src/period.c(321) : error C2065: 'row_index' : undeclared identifier
pandas/src/period.c(322) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(323) : error C2065: 'column_index' : undeclared identifier
pandas/src/period.c(323) : error C2065: 'column_index' : undeclared identifier
pandas/src/period.c(323) : error C2065: 'column_index' : undeclared identifier
pandas/src/period.c(324) : error C2065: 'row_index' : undeclared identifier
pandas/src/period.c(324) : error C2065: 'column_index' : undeclared identifier
pandas/src/period.c(360) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(361) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(362) : error C2065: 'column_index_index' : undeclared identifier
pandas/src/period.c(362) : error C2065: 'column_index_index' : undeclared identifier
pandas/src/period.c(363) : error C2065: 'column_index_index' : undeclared identifier
pandas/src/period.c(367) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(369) : error C2065: 'row_index' : undeclared identifier
pandas/src/period.c(369) : error C2065: 'column_index' : undeclared identifier
pandas/src/period.c(394) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(395) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(397) : error C2275: 'npy_int64' : illegal use of this type as an expression
        c:\python27\lib\site-packages\numpy\core\include\numpy\npy_common.h(443) : see declaration of 'npy_int64'
pandas/src/period.c(397) : error C2146: syntax error : missing ';' before identifier 'conversion_factor'
pandas/src/period.c(397) : error C2065: 'conversion_factor' : undeclared identifier
pandas/src/period.c(397) : error C2065: 'from_index' : undeclared identifier
pandas/src/period.c(397) : error C2065: 'to_index' : undeclared identifier
pandas/src/period.c(397) : warning C4244: '=' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(399) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(402) : error C2065: 'offset' : undeclared identifier
pandas/src/period.c(402) : error C2065: 'conversion_factor' : undeclared identifier
pandas/src/period.c(402) : error C2065: 'offset' : undeclared identifier
pandas/src/period.c(404) : error C2065: 'conversion_factor' : undeclared identifier
pandas/src/period.c(412) : error C2275: 'npy_int64' : illegal use of this type as an expression
        c:\python27\lib\site-packages\numpy\core\include\numpy\npy_common.h(443) : see declaration of 'npy_int64'
pandas/src/period.c(412) : error C2146: syntax error : missing ';' before identifier 'result'
pandas/src/period.c(412) : error C2065: 'result' : undeclared identifier
pandas/src/period.c(412) : warning C4244: '=' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(417) : error C2065: 'result' : undeclared identifier
pandas/src/period.c(417) : error C2065: 'result' : undeclared identifier
pandas/src/period.c(417) : warning C4244: '=' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(420) : error C2065: 'result' : undeclared identifier
pandas/src/period.c(456) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(457) : error C2065: 'dinfo' : undeclared identifier
pandas/src/period.c(457) : warning C4133: 'function' : incompatible types - from 'int *' to 'date_info *'
pandas/src/period.c(459) : error C2065: 'dinfo' : undeclared identifier
pandas/src/period.c(459) : error C2224: left of '.month' must have struct/union type
pandas/src/period.c(460) : error C2065: 'dinfo' : undeclared identifier
pandas/src/period.c(460) : error C2224: left of '.year' must have struct/union type
pandas/src/period.c(460) : warning C4033: 'asfreq_DTtoA' must return a value
pandas/src/period.c(463) : error C2065: 'dinfo' : undeclared identifier
pandas/src/period.c(463) : error C2224: left of '.year' must have struct/union type
pandas/src/period.c(463) : warning C4033: 'asfreq_DTtoA' must return a value
pandas/src/period.c(488) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(490) : error C2065: 'year' : undeclared identifier
pandas/src/period.c(490) : error C2065: 'quarter' : undeclared identifier
pandas/src/period.c(494) : error C2065: 'year' : undeclared identifier
pandas/src/period.c(494) : error C2065: 'quarter' : undeclared identifier
pandas/src/period.c(501) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(502) : error C2065: 'dinfo' : undeclared identifier
pandas/src/period.c(502) : warning C4133: 'function' : incompatible types - from 'int *' to 'date_info *'
pandas/src/period.c(504) : error C2065: 'dinfo' : undeclared identifier
pandas/src/period.c(504) : error C2224: left of '.year' must have struct/union type
pandas/src/period.c(504) : error C2065: 'dinfo' : undeclared identifier
pandas/src/period.c(504) : error C2224: left of '.month' must have struct/union type
pandas/src/period.c(504) : warning C4033: 'asfreq_DTtoM' must return a value
pandas/src/period.c(515) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(516) : error C2065: 'dinfo' : undeclared identifier
pandas/src/period.c(516) : warning C4133: 'function' : incompatible types - from 'int *' to 'date_info *'
pandas/src/period.c(520) : error C2065: 'dinfo' : undeclared identifier
pandas/src/period.c(520) : error C2224: left of '.absdate' must have struct/union type
pandas/src/period.c(520) : error C2065: 'dinfo' : undeclared identifier
pandas/src/period.c(520) : error C2224: left of '.day_of_week' must have struct/union type
pandas/src/period.c(520) : error C2198: 'DtoB_WeekendToFriday' : too few arguments for call
pandas/src/period.c(522) : error C2065: 'dinfo' : undeclared identifier
pandas/src/period.c(522) : error C2224: left of '.absdate' must have struct/union type
pandas/src/period.c(522) : error C2065: 'dinfo' : undeclared identifier
pandas/src/period.c(522) : error C2224: left of '.day_of_week' must have struct/union type
pandas/src/period.c(522) : error C2198: 'DtoB_WeekendToMonday' : too few arguments for call
pandas/src/period.c(541) : warning C4244: 'function' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(615) : warning C4244: 'function' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(616) : warning C4244: 'function' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(667) : warning C4244: 'function' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(668) : warning C4244: 'function' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(747) : warning C4244: 'function' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(809) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(810) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(812) : error C2065: 'fromGroup' : undeclared identifier
pandas/src/period.c(815) : error C2065: 'fromGroup' : undeclared identifier
pandas/src/period.c(818) : error C2065: 'fromGroup' : undeclared identifier
pandas/src/period.c(821) : error C2065: 'fromGroup' : undeclared identifier
pandas/src/period.c(825) : error C2065: 'toGroup' : undeclared identifier
pandas/src/period.c(828) : error C2065: 'toGroup' : undeclared identifier
pandas/src/period.c(831) : error C2065: 'toGroup' : undeclared identifier
pandas/src/period.c(834) : error C2065: 'toGroup' : undeclared identifier
pandas/src/period.c(840) : error C2061: syntax error : identifier 'get_asfreq_func'
pandas/src/period.c(840) : error C2059: syntax error : ';'
pandas/src/period.c(840) : error C2059: syntax error : 'type'
pandas/src/period.c(985) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(986) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(987) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(991) : error C2275: 'npy_int64' : illegal use of this type as an expression
        c:\python27\lib\site-packages\numpy\core\include\numpy\npy_common.h(443) : see declaration of 'npy_int64'
pandas/src/period.c(991) : error C2146: syntax error : missing ';' before identifier 'per_day'
pandas/src/period.c(991) : error C2065: 'per_day' : undeclared identifier
pandas/src/period.c(991) : error C2065: 'day_index' : undeclared identifier
pandas/src/period.c(991) : error C2065: 'freq_index' : undeclared identifier
pandas/src/period.c(991) : warning C4244: '=' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(992) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(996) : error C2065: 'base_index' : undeclared identifier
pandas/src/period.c(996) : error C2065: 'freq_index' : undeclared identifier
pandas/src/period.c(997) : error C2065: 'unit' : undeclared identifier
pandas/src/period.c(997) : error C2065: 'unit' : undeclared identifier
pandas/src/period.c(1001) : error C2275: 'npy_int64' : illegal use of this type as an expression
        c:\python27\lib\site-packages\numpy\core\include\numpy\npy_common.h(443) : see declaration of 'npy_int64'
pandas/src/period.c(1001) : error C2146: syntax error : missing ';' before identifier 'start_ord'
pandas/src/period.c(1001) : error C2065: 'start_ord' : undeclared identifier
pandas/src/period.c(1001) : fatal error C1003: error count exceeds 100; stopping compilation
error: command '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\amd64\cl.exe"' failed with exit status 2
PS H:\jreback\pandas>
PS H:\jreback\pandas>
PS H:\jreback\pandas>
```

Moved the tslib test code to the right position and removed inline statements from period.c which are not supported by MSVC and not really required with modern compilers.

```
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Ipandas/src/klib -Ipandas/src -IC:\python27\lib\site-packages\numpy\core\include -IC:\python27\include -IC:\p
thon27\PC /Tcpandas/src/period.c /Fobuild\temp.win-amd64-2.7\Release\pandas/src/period.obj
period.c
c:\python27\lib\site-packages\numpy\core\include\numpy\npy_deprecated_api.h(8) : Warning Msg: Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
pandas/src/period.c(86) : warning C4244: 'return' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(88) : warning C4244: 'return' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(92) : warning C4244: 'return' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(94) : warning C4244: 'return' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(226) : warning C4244: '=' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(237) : warning C4244: '=' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(288) : error C2059: syntax error : 'type'
pandas/src/period.c(292) : error C2059: syntax error : 'type'
pandas/src/period.c(319) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(320) : error C2065: 'row_index' : undeclared identifier
pandas/src/period.c(320) : error C2065: 'row_index' : undeclared identifier
pandas/src/period.c(320) : error C2065: 'row_index' : undeclared identifier
pandas/src/period.c(321) : error C2065: 'row_index' : undeclared identifier
pandas/src/period.c(322) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(323) : error C2065: 'column_index' : undeclared identifier
pandas/src/period.c(323) : error C2065: 'column_index' : undeclared identifier
pandas/src/period.c(323) : error C2065: 'column_index' : undeclared identifier
pandas/src/period.c(324) : error C2065: 'row_index' : undeclared identifier
pandas/src/period.c(324) : error C2065: 'column_index' : undeclared identifier
pandas/src/period.c(360) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(361) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(362) : error C2065: 'column_index_index' : undeclared identifier
pandas/src/period.c(362) : error C2065: 'column_index_index' : undeclared identifier
pandas/src/period.c(363) : error C2065: 'column_index_index' : undeclared identifier
pandas/src/period.c(367) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(369) : error C2065: 'row_index' : undeclared identifier
pandas/src/period.c(369) : error C2065: 'column_index' : undeclared identifier
pandas/src/period.c(394) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(395) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(397) : error C2275: 'npy_int64' : illegal use of this type as an expression
        c:\python27\lib\site-packages\numpy\core\include\numpy\npy_common.h(443) : see declaration of 'npy_int64'
pandas/src/period.c(397) : error C2146: syntax error : missing ';' before identifier 'conversion_factor'
pandas/src/period.c(397) : error C2065: 'conversion_factor' : undeclared identifier
pandas/src/period.c(397) : error C2065: 'from_index' : undeclared identifier
pandas/src/period.c(397) : error C2065: 'to_index' : undeclared identifier
pandas/src/period.c(397) : warning C4244: '=' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(399) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(402) : error C2065: 'offset' : undeclared identifier
pandas/src/period.c(402) : error C2065: 'conversion_factor' : undeclared identifier
pandas/src/period.c(402) : error C2065: 'offset' : undeclared identifier
pandas/src/period.c(404) : error C2065: 'conversion_factor' : undeclared identifier
pandas/src/period.c(412) : error C2275: 'npy_int64' : illegal use of this type as an expression
        c:\python27\lib\site-packages\numpy\core\include\numpy\npy_common.h(443) : see declaration of 'npy_int64'
pandas/src/period.c(412) : error C2146: syntax error : missing ';' before identifier 'result'
pandas/src/period.c(412) : error C2065: 'result' : undeclared identifier
pandas/src/period.c(412) : warning C4244: '=' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(417) : error C2065: 'result' : undeclared identifier
pandas/src/period.c(417) : error C2065: 'result' : undeclared identifier
pandas/src/period.c(417) : warning C4244: '=' : conversion from 'npy_int64' to 'int', possible loss of data
pandas/src/period.c(420) : error C2065: 'result' : undeclared identifier
pandas/src/period.c(456) : error C2143: syntax error : missing ';' before 'type'
pandas/src/period.c(457) : error C2065: 'dinfo' : undeclared identifier
pandas/src/period.c(457) : warning C4133: 'function' : incompatible types - from 'int *' to 'date_info *'
```