Skip to content

Commit e58292f

Browse files
minggliharisbal
authored and
harisbal
committed
Regression in make_block_same_class (tests failing for new fastparquet release) (pandas-dev#19434)
1 parent a0045c8 commit e58292f

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

doc/source/io.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -4537,7 +4537,7 @@ See the documentation for `pyarrow <http://arrow.apache.org/docs/python/>`__ and
45374537
.. note::
45384538

45394539
These engines are very similar and should read/write nearly identical parquet format files.
4540-
Currently ``pyarrow`` does not support timedelta data, and ``fastparquet`` does not support timezone aware datetimes (they are coerced to UTC).
4540+
Currently ``pyarrow`` does not support timedelta data, ``fastparquet>=0.1.4`` supports timezone aware datetimes.
45414541
These libraries differ by having different underlying dependencies (``fastparquet`` by using ``numba``, while ``pyarrow`` uses a c-library).
45424542

45434543
.. ipython:: python

pandas/core/internals.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,17 @@ def make_block_scalar(self, values):
224224
"""
225225
return ScalarBlock(values)
226226

227-
def make_block_same_class(self, values, placement=None, ndim=None):
227+
def make_block_same_class(self, values, placement=None, ndim=None,
228+
dtype=None):
228229
""" Wrap given values in a block of same type as self. """
230+
if dtype is not None:
231+
# issue 19431 fastparquet is passing this
232+
warnings.warn("dtype argument is deprecated, will be removed "
233+
"in a future release.", FutureWarning)
229234
if placement is None:
230235
placement = self.mgr_locs
231236
return make_block(values, placement=placement, ndim=ndim,
232-
klass=self.__class__)
237+
klass=self.__class__, dtype=dtype)
233238

234239
def __unicode__(self):
235240

pandas/tests/internals/test_internals.py

+7
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ def test_delete(self):
285285
with pytest.raises(Exception):
286286
newb.delete(3)
287287

288+
def test_make_block_same_class(self):
289+
# issue 19431
290+
block = create_block('M8[ns, US/Eastern]', [3])
291+
with tm.assert_produces_warning(FutureWarning,
292+
check_stacklevel=False):
293+
block.make_block_same_class(block.values, dtype=block.values.dtype)
294+
288295

289296
class TestDatetimeBlock(object):
290297

pandas/tests/io/test_parquet.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ def fp():
7171
return 'fastparquet'
7272

7373

74+
@pytest.fixture
75+
def fp_lt_014():
76+
if not _HAVE_FASTPARQUET:
77+
pytest.skip("fastparquet is not installed")
78+
if LooseVersion(fastparquet.__version__) >= LooseVersion('0.1.4'):
79+
pytest.skip("fastparquet is >= 0.1.4")
80+
return 'fastparquet'
81+
82+
7483
@pytest.fixture
7584
def df_compat():
7685
return pd.DataFrame({'A': [1, 2, 3], 'B': 'foo'})
@@ -435,8 +444,10 @@ def test_basic(self, fp, df_full):
435444
df = df_full
436445

437446
# additional supported types for fastparquet
447+
if LooseVersion(fastparquet.__version__) >= LooseVersion('0.1.4'):
448+
df['datetime_tz'] = pd.date_range('20130101', periods=3,
449+
tz='US/Eastern')
438450
df['timedelta'] = pd.timedelta_range('1 day', periods=3)
439-
440451
check_round_trip(df, fp)
441452

442453
@pytest.mark.skip(reason="not supported")
@@ -468,14 +479,15 @@ def test_categorical(self, fp):
468479
df = pd.DataFrame({'a': pd.Categorical(list('abc'))})
469480
check_round_trip(df, fp)
470481

471-
def test_datetime_tz(self, fp):
472-
# doesn't preserve tz
482+
def test_datetime_tz(self, fp_lt_014):
483+
484+
# fastparquet<0.1.4 doesn't preserve tz
473485
df = pd.DataFrame({'a': pd.date_range('20130101', periods=3,
474486
tz='US/Eastern')})
475-
476487
# warns on the coercion
477488
with catch_warnings(record=True):
478-
check_round_trip(df, fp, expected=df.astype('datetime64[ns]'))
489+
check_round_trip(df, fp_lt_014,
490+
expected=df.astype('datetime64[ns]'))
479491

480492
def test_filter_row_groups(self, fp):
481493
d = {'a': list(range(0, 3))}

0 commit comments

Comments
 (0)