Skip to content

BUG: pd.concat inconsistent behaviour with empty and tz-aware Series #34174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dave-cz opened this issue May 14, 2020 · 4 comments · Fixed by #56685
Closed

BUG: pd.concat inconsistent behaviour with empty and tz-aware Series #34174

dave-cz opened this issue May 14, 2020 · 4 comments · Fixed by #56685
Assignees
Labels
Bug Needs Tests Unit test(s) needed to prevent regressions Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timezones Timezone data dtype

Comments

@dave-cz
Copy link

dave-cz commented May 14, 2020

df = pd.concat([
    pd.Series(dtype=float), 
    pd.Series(index=[pd.Timestamp('2020-01-01T00:00:00+00:00')], data=0, dtype=float)], 
axis=1)
>>> df
                            0    1
2020-01-01 00:00:00+00:00 NaN  0.0
df = pd.concat([
    pd.Series(index=[pd.Timestamp('2020-01-01T00:00:00')], data=0, dtype=float), 
    pd.Series(dtype=float)],    
axis=1)
>>> df
              0   1
2020-01-01  0.0 NaN
df = pd.concat([
    pd.Series(index=[pd.Timestamp('2020-01-01T00:00:00+00:00')], data=0, dtype=float), 
    pd.Series(dtype=float)], 
axis=1)

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\reshape\concat.py", line 281, in concat
    sort=sort,
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\reshape\concat.py", line 452, in __init__
    self.new_axes = self._get_new_axes()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\reshape\concat.py", line 517, in _get_new_axes
    for i in range(ndim)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\reshape\concat.py", line 517, in <listcomp>
    for i in range(ndim)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\reshape\concat.py", line 523, in _get_comb_axis
    self.objs, axis=data_axis, intersect=self.intersect, sort=self.sort
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\indexes\api.py", line 90, in get_objs_combined_axis
    return _get_combined_index(obs_idxes, intersect=intersect, sort=sort)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\indexes\api.py", line 138, in _get_combined_index
    index = union_indexes(indexes, sort=sort)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\indexes\api.py", line 202, in union_indexes
    return result.union_many(indexes[1:])
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\indexes\datetimes.py", line 363, in union_many
    this, other = this._maybe_utc_convert(other)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\indexes\datetimelike.py", line 832, in _maybe_utc_convert
    raise TypeError("Cannot join tz-naive with tz-aware DatetimeIndex")
TypeError: Cannot join tz-naive with tz-aware DatetimeIndex

INSTALLED VERSIONS

commit : None
python : 3.7.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 1.0.3
numpy : 1.16.4
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.1.3
Cython : 0.29.14
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.3.4
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.3.4
matplotlib : 3.1.1
numexpr : 2.7.0
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : 1.3.0
sqlalchemy : 1.3.16
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : 0.45.1

@dave-cz dave-cz added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 14, 2020
@jreback
Copy link
Contributor

jreback commented May 14, 2020

pls try on master

@jorisvandenbossche
Copy link
Member

On master, there is still exactly the same error.

@dave-cz thanks for the report!

@jorisvandenbossche jorisvandenbossche added Reshaping Concat, Merge/Join, Stack/Unstack, Explode and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 14, 2020
@jorisvandenbossche jorisvandenbossche added this to the Contributions Welcome milestone May 14, 2020
@mroeschke mroeschke added the Timezones Timezone data dtype label Aug 7, 2021
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
@jbrockmendel
Copy link
Member

This works for me on main. Could use a test

@jbrockmendel jbrockmendel added the Needs Tests Unit test(s) needed to prevent regressions label May 19, 2023
@xiaohuanlin
Copy link
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Tests Unit test(s) needed to prevent regressions Reshaping Concat, Merge/Join, Stack/Unstack, Explode Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants