Skip to content

Commit 2213e18

Browse files
committed
Merge pull request #12013 from kawochen/BUG-FIX-11880
BUG: GH11880 where __contains__ fails in unpacked DataFrame with object cols
2 parents d0655a6 + 7f044b7 commit 2213e18

File tree

4 files changed

+72
-8
lines changed

4 files changed

+72
-8
lines changed

doc/source/whatsnew/v0.18.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ Bug Fixes
463463
- Bug in ``pd.read_clipboard`` and ``pd.to_clipboard`` functions not supporting Unicode; upgrade included ``pyperclip`` to v1.5.15 (:issue:`9263`)
464464
- Bug in ``DataFrame.query`` containing an assignment (:issue:`8664`)
465465

466+
- Bug in ``from_msgpack`` where ``__contains__()`` fails for columns of the unpacked ``DataFrame``, if the ``DataFrame`` has object columns. (:issue: `11880`)
466467

467468

468469
- Bug in timezone info lost when broadcasting scalar datetime to ``DataFrame`` (:issue:`11682`)

pandas/core/window.py

+1
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ def corr(self, other=None, pairwise=None, **kwargs):
965965
Use a standard estimation bias correction
966966
"""
967967

968+
968969
class EWM(_Rolling):
969970
r"""
970971
Provides exponential weighted functions

pandas/hashtable.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ cdef class Int64HashTable(HashTable):
342342
self.table.vals[k] = <Py_ssize_t> values[i]
343343

344344
@cython.boundscheck(False)
345-
def map_locations(self, int64_t[:] values):
345+
def map_locations(self, ndarray[int64_t, ndim=1] values):
346346
cdef:
347347
Py_ssize_t i, n = len(values)
348348
int ret = 0
@@ -570,7 +570,7 @@ cdef class Float64HashTable(HashTable):
570570
return np.asarray(labels)
571571

572572
@cython.boundscheck(False)
573-
def map_locations(self, float64_t[:] values):
573+
def map_locations(self, ndarray[float64_t, ndim=1] values):
574574
cdef:
575575
Py_ssize_t i, n = len(values)
576576
int ret = 0

pandas/io/tests/test_packers.py

+68-6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from pandas import compat
1010
from pandas.compat import u
1111
from pandas import (Series, DataFrame, Panel, MultiIndex, bdate_range,
12-
date_range, period_range, Index, SparseSeries, SparseDataFrame,
13-
SparsePanel)
12+
date_range, period_range, Index)
13+
from pandas.io.packers import to_msgpack, read_msgpack
1414
import pandas.util.testing as tm
1515
from pandas.util.testing import (ensure_clean, assert_index_equal,
1616
assert_series_equal,
@@ -23,7 +23,19 @@
2323

2424
nan = np.nan
2525

26-
from pandas.io.packers import to_msgpack, read_msgpack
26+
try:
27+
import blosc # NOQA
28+
except ImportError:
29+
_BLOSC_INSTALLED = False
30+
else:
31+
_BLOSC_INSTALLED = True
32+
33+
try:
34+
import zlib # NOQA
35+
except ImportError:
36+
_ZLIB_INSTALLED = False
37+
else:
38+
_ZLIB_INSTALLED = True
2739

2840
_multiprocess_can_split_ = False
2941

@@ -483,6 +495,14 @@ class TestCompression(TestPackers):
483495
"""
484496

485497
def setUp(self):
498+
try:
499+
from sqlalchemy import create_engine
500+
self._create_sql_engine = create_engine
501+
except ImportError:
502+
self._SQLALCHEMY_INSTALLED = False
503+
else:
504+
self._SQLALCHEMY_INSTALLED = True
505+
486506
super(TestCompression, self).setUp()
487507
data = {
488508
'A': np.arange(1000, dtype=np.float64),
@@ -508,14 +528,56 @@ def test_compression_zlib(self):
508528
assert_frame_equal(self.frame[k], i_rec[k])
509529

510530
def test_compression_blosc(self):
511-
try:
512-
import blosc
513-
except ImportError:
531+
if not _BLOSC_INSTALLED:
514532
raise nose.SkipTest('no blosc')
515533
i_rec = self.encode_decode(self.frame, compress='blosc')
516534
for k in self.frame.keys():
517535
assert_frame_equal(self.frame[k], i_rec[k])
518536

537+
def test_readonly_axis_blosc(self):
538+
# GH11880
539+
if not _BLOSC_INSTALLED:
540+
raise nose.SkipTest('no blosc')
541+
df1 = DataFrame({'A': list('abcd')})
542+
df2 = DataFrame(df1, index=[1., 2., 3., 4.])
543+
self.assertTrue(1 in self.encode_decode(df1['A'], compress='blosc'))
544+
self.assertTrue(1. in self.encode_decode(df2['A'], compress='blosc'))
545+
546+
def test_readonly_axis_zlib(self):
547+
# GH11880
548+
df1 = DataFrame({'A': list('abcd')})
549+
df2 = DataFrame(df1, index=[1., 2., 3., 4.])
550+
self.assertTrue(1 in self.encode_decode(df1['A'], compress='zlib'))
551+
self.assertTrue(1. in self.encode_decode(df2['A'], compress='zlib'))
552+
553+
def test_readonly_axis_blosc_to_sql(self):
554+
# GH11880
555+
if not _BLOSC_INSTALLED:
556+
raise nose.SkipTest('no blosc')
557+
if not self._SQLALCHEMY_INSTALLED:
558+
raise nose.SkipTest('no sqlalchemy')
559+
expected = DataFrame({'A': list('abcd')})
560+
df = self.encode_decode(expected, compress='blosc')
561+
eng = self._create_sql_engine("sqlite:///:memory:")
562+
df.to_sql('test', eng, if_exists='append')
563+
result = pandas.read_sql_table('test', eng, index_col='index')
564+
result.index.names = [None]
565+
assert_frame_equal(expected, result)
566+
567+
def test_readonly_axis_zlib_to_sql(self):
568+
# GH11880
569+
if not _ZLIB_INSTALLED:
570+
raise nose.SkipTest('no zlib')
571+
if not self._SQLALCHEMY_INSTALLED:
572+
raise nose.SkipTest('no sqlalchemy')
573+
expected = DataFrame({'A': list('abcd')})
574+
df = self.encode_decode(expected, compress='zlib')
575+
eng = self._create_sql_engine("sqlite:///:memory:")
576+
df.to_sql('test', eng, if_exists='append')
577+
result = pandas.read_sql_table('test', eng, index_col='index')
578+
result.index.names = [None]
579+
assert_frame_equal(expected, result)
580+
519581

520582
class TestEncoding(TestPackers):
521583
def setUp(self):

0 commit comments

Comments
 (0)