Skip to content

concat(..., copy=False) with datetime tz-aware data raises ValueError: cannot create a DatetimeTZBlock without a tz #25257

Closed
@karldw

Description

@karldw

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.DataFrame({
    'timestamp': [pd.Timestamp('2017-08-27 01:00:00.709949+0000', tz='UTC')],
})

pd.concat([df])      # works
pd.concat([df, df])  # works
pd.concat([df], copy=False)  # fails
# Edit: added full traceback
# Traceback (most recent call last):
#   File "<stdin>", line 1, in <module>
#   File ".../pandas/core/reshape/concat.py", line 229, in concat
#     return op.get_result()
#   File ".../pandas/core/reshape/concat.py", line 426, in get_result
#     copy=self.copy)
#   File ".../pandas/core/internals/managers.py", line 2055, in concatenate_block_managers
#     b = b.make_block_same_class(values, placement=placement)
#   File ".../pandas/core/internals/blocks.py", line 235, in make_block_same_class
#     klass=self.__class__, dtype=dtype)
#   File ".../pandas/core/internals/blocks.py", line 3095, in make_block
#     return klass(values, ndim=ndim, placement=placement)
#   File ".../pandas/core/internals/blocks.py", line 1680, in __init__
#     values = self._maybe_coerce_values(values)
#   File ".../pandas/core/internals/blocks.py", line 2266, in _maybe_coerce_values
#     raise ValueError("cannot create a DatetimeTZBlock without a tz")
# ValueError: cannot create a DatetimeTZBlock without a tz

Problem description

Running pd.concat with a single dataframe and copy=False fails, giving an error about cannot create a DatetimeTZBlock without a tz.

Closely related:

Expected Output

The original dataframe, since I'm only concat-ing a single dataframe.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.8.final.0
python-bits: 64
OS: Linux
OS-release: 4.18.0-14-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.1
pytest: 4.2.0
pip: 19.0.1
setuptools: 40.6.3
Cython: 0.29.4
numpy: 1.15.4
scipy: 1.2.0
pyarrow: 0.11.1
xarray: None
IPython: 7.2.0
sphinx: None
patsy: None
dateutil: 2.7.5
pytz: 2018.7
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.2
openpyxl: 2.4.10
xlrd: 1.2.0
xlwt: None
xlsxwriter: 1.1.2
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: 1.2.17
pymysql: None
psycopg2: 2.7.6.1 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: 0.2.1
pandas_gbq: None
pandas_datareader: None
gcsfs: None

Metadata

Metadata

Assignees

Labels

Needs TestsUnit test(s) needed to prevent regressionsReshapingConcat, Merge/Join, Stack/Unstack, ExplodeTimezonesTimezone data dtypegood first issue

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions