@@ -27,6 +27,9 @@ having to do with nanosecond resolution data, so I recommend that you steer
27
27
clear of NumPy 1.6's datetime64 API functions (though limited as they are) and
28
28
only interact with this data using the interface that pandas provides.
29
29
30
+ See the end of the 0.8.0 section for a "porting" guide listing potential issues
31
+ for users migrating legacy codebases from pandas 0.7 or earlier to 0.8.0.
32
+
30
33
Bug fixes to the 0.7.x series for legacy NumPy < 1.6 users will be provided as
31
34
they arise. There will be no more further development in 0.7.x beyond bug
32
35
fixes.
@@ -146,3 +149,85 @@ Other API changes
146
149
147
150
- Deprecation of ``offset``, ``time_rule``, and ``timeRule`` arguments names in
148
151
time series functions. Warnings will be printed until pandas 0.9 or 1.0.
152
+
153
+ Potential porting issues for pandas <= 0.7.3 users
154
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
155
+
156
+ The major change that may affect you in pandas 0.8.0 is that time series
157
+ indexes use NumPy's ``datetime64`` data type instead of ``dtype=object`` arrays
158
+ of Python's built-in ``datetime.datetime`` objects. ``DateRange`` has been
159
+ replaced by ``DatetimeIndex`` but otherwise behaved identically. But, if you
160
+ have code that converts ``DateRange`` or ``Index`` objects that used to contain
161
+ ``datetime.datetime`` values to plain NumPy arrays, you may have bugs lurking
162
+ with code using scalar values because you are handing control over to NumPy:
163
+
164
+ .. ipython:: python
165
+
166
+ import datetime
167
+ rng = date_range('1/1/2000', periods=10)
168
+ rng[5]
169
+ isinstance(rng[5], datetime.datetime)
170
+ rng_asarray = np.asarray(rng)
171
+ scalar_val = rng_asarray[5]
172
+ type(scalar_val)
173
+
174
+ pandas's ``Timestamp`` object is a subclass of ``datetime.datetime`` that has
175
+ nanosecond support (the ``nanosecond`` field store the nanosecond value between
176
+ 0 and 999). It should substitute directly into any code that used
177
+ ``datetime.datetime`` values before. Thus, I recommend not casting
178
+ ``DatetimeIndex`` to regular NumPy arrays.
179
+
180
+ If you have code that requires an array of ``datetime.datetime`` objects, you
181
+ have a couple of options. First, the ``asobject`` property of ``DatetimeIndex``
182
+ produces an array of ``Timestamp`` objects:
183
+
184
+ .. ipython:: python
185
+
186
+ stamp_array = rng.asobject
187
+ stamp_array
188
+ stamp_array[5]
189
+
190
+ To get an array of proper ``datetime.datetime`` objects, use the
191
+ ``to_pydatetime`` method:
192
+
193
+ .. ipython:: python
194
+
195
+ dt_array = rng.to_pydatetime()
196
+ dt_array
197
+ dt_array[5]
198
+
199
+ matplotlib knows how to handle ``datetime.datetime`` but not Timestamp
200
+ objects. While I recommend that you plot time series using ``TimeSeries.plot``,
201
+ you can either use ``to_pydatetime`` or register a converter for the Timestamp
202
+ type. See `matplotlib documentation
203
+ <http://matplotlib.sourceforge.net/api/units_api.html>`__ for more on this.
204
+
205
+ .. warning::
206
+
207
+ There are bugs in the user-facing API with the nanosecond datetime64 unit
208
+ in NumPy 1.6. In particular, the string version of the array shows garbage
209
+ values, and conversion to ``dtype=object`` is similarly broken.
210
+
211
+ .. ipython:: python
212
+
213
+ rng = date_range('1/1/2000', periods=10)
214
+ rng
215
+ np.asarray(rng)
216
+ converted = np.asarray(rng, dtype=object)
217
+ converted[5]
218
+
219
+ **Trust me: don't panic**. If you are using NumPy 1.6 and restrict your
220
+ interaction with ``datetime64`` values to pandas's API you will be just
221
+ fine. There is nothing wrong with the data-type (a 64-bit integer
222
+ internally); all of the important data processing happens in pandas and is
223
+ heavily tested. I strongly recommend that you **do not work directly with
224
+ datetime64 arrays in NumPy 1.6** and only use the pandas API.
225
+
226
+
227
+ **Support for non-unique indexes**: In the latter case, you may have code
228
+ inside a ``try:... catch:`` block that failed due to the index not being
229
+ unique. In many cases it will no longer fail (some method like ``append`` still
230
+ check for uniqueness unless disabled). However, all is not lost: you can
231
+ inspect ``index.is_unique`` and raise an exception explicitly if it is
232
+ ``False`` or go to a different code branch.
233
+
0 commit comments