Skip to content

Commit 3358afc

Browse files
kawochenjreback
authored andcommitted
DEPR: GH10623 remove items from msgpack.encode for blocks
closes pandas-dev#10623 closes pandas-dev#12129
1 parent 6fecc93 commit 3358afc

13 files changed

+370
-246
lines changed

doc/source/io.rst

+18
Original file line numberDiff line numberDiff line change
@@ -2539,6 +2539,24 @@ both on the writing (serialization), and reading (deserialization).
25392539
optimizations in the io of the ``msgpack`` data. Since this is marked
25402540
as an EXPERIMENTAL LIBRARY, the storage format may not be stable until a future release.
25412541

2542+
As a result of writing format changes and other issues:
2543+
+----------------------+------------------------+
2544+
| Packed with | Can be unpacked with |
2545+
+======================+========================+
2546+
| pre-0.17 / Python 2 | any |
2547+
+----------------------+------------------------+
2548+
| pre-0.17 / Python 3 | any |
2549+
+----------------------+------------------------+
2550+
| 0.17 / Python 2 | - 0.17 / Python 2 |
2551+
| | - >=0.18 / any Python |
2552+
+----------------------+------------------------+
2553+
| 0.17 / Python 3 | >=0.18 / any Python |
2554+
+----------------------+------------------------+
2555+
| 0.18 | >= 0.18 |
2556+
+======================+========================+
2557+
2558+
Reading (files packed by older versions) is backward-compatibile, except for files packed with 0.17 in Python 2, in which case only they can only be unpacked in Python 2.
2559+
25422560
.. ipython:: python
25432561
25442562
df = DataFrame(np.random.rand(5,2),columns=list('AB'))

doc/source/whatsnew/v0.18.0.txt

+27-1
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,33 @@ Subtraction by ``Timedelta`` in a ``Series`` by a ``Timestamp`` works (:issue:`1
513513
``pd.Timestamp`` to rehydrate any timestamp like object from its isoformat
514514
(:issue:`12300`).
515515

516+
Changes to msgpack
517+
^^^^^^^^^^^^^^^^^^
518+
519+
Forward incompatible changes in ``msgpack`` writing format were made over 0.17.0 and 0.18.0; older versions of pandas cannot read files packed by newer versions (:issue:`12129`, `10527`)
520+
521+
Bug in ``to_msgpack`` and ``read_msgpack`` introduced in 0.17.0 and fixed in 0.18.0, caused files packed in Python 2 unreadable by Python 3 (:issue:`12142`)
522+
523+
.. warning::
524+
525+
As a result of a number of issues:
526+
527+
+----------------------+------------------------+
528+
| Packed with | Can be unpacked with |
529+
+======================+========================+
530+
| pre-0.17 / Python 2 | any |
531+
+----------------------+------------------------+
532+
| pre-0.17 / Python 3 | any |
533+
+----------------------+------------------------+
534+
| 0.17 / Python 2 | - 0.17 / Python 2 |
535+
| | - >=0.18 / any Python |
536+
+----------------------+------------------------+
537+
| 0.17 / Python 3 | >=0.18 / any Python |
538+
+----------------------+------------------------+
539+
| 0.18 | >= 0.18 |
540+
+======================+========================+
541+
542+
0.18.0 is backward-compatible for reading files packed by older versions, except for files packed with 0.17 in Python 2, in which case only they can only be unpacked in Python 2.
516543

517544
Signature change for .rank
518545
^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -806,7 +833,6 @@ assignments are valid for multi-line expressions.
806833

807834
Other API Changes
808835
^^^^^^^^^^^^^^^^^
809-
810836
- ``DataFrame.between_time`` and ``Series.between_time`` now only parse a fixed set of time strings. Parsing of date strings is no longer supported and raises a ``ValueError``. (:issue:`11818`)
811837

812838
.. ipython:: python

pandas/core/common.py

+26
Original file line numberDiff line numberDiff line change
@@ -3039,3 +3039,29 @@ def _random_state(state=None):
30393039
else:
30403040
raise ValueError("random_state must be an integer, a numpy "
30413041
"RandomState, or None")
3042+
3043+
3044+
def pandas_dtype(dtype):
3045+
"""
3046+
Converts input into a pandas only dtype object or a numpy dtype object.
3047+
3048+
Parameters
3049+
----------
3050+
dtype : object to be converted
3051+
3052+
Returns
3053+
-------
3054+
np.dtype or a pandas dtype
3055+
"""
3056+
if isinstance(dtype, compat.string_types):
3057+
try:
3058+
return DatetimeTZDtype.construct_from_string(dtype)
3059+
except TypeError:
3060+
pass
3061+
3062+
try:
3063+
return CategoricalDtype.construct_from_string(dtype)
3064+
except TypeError:
3065+
pass
3066+
3067+
return np.dtype(dtype)

pandas/core/internals.py

+12
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,14 @@ def __init__(self, values, placement, ndim=2, **kwargs):
20982098

20992099
if not isinstance(values, self._holder):
21002100
values = self._holder(values)
2101+
2102+
dtype = kwargs.pop('dtype', None)
2103+
2104+
if dtype is not None:
2105+
if isinstance(dtype, compat.string_types):
2106+
dtype = DatetimeTZDtype.construct_from_string(dtype)
2107+
values = values.tz_localize('UTC').tz_convert(dtype.tz)
2108+
21012109
if values.tz is None:
21022110
raise ValueError("cannot create a DatetimeTZBlock without a tz")
21032111

@@ -2428,6 +2436,10 @@ def make_block(values, placement, klass=None, ndim=None, dtype=None,
24282436
else:
24292437
klass = ObjectBlock
24302438

2439+
elif klass is DatetimeTZBlock and not is_datetimetz(values):
2440+
return klass(values, ndim=ndim, fastpath=fastpath,
2441+
placement=placement, dtype=dtype)
2442+
24312443
return klass(values, ndim=ndim, fastpath=fastpath, placement=placement)
24322444

24332445
# TODO: flexible with index=None and/or items=None

0 commit comments

Comments
 (0)