Skip to content

BUG: concatenation on monthstart indexes in wrong timezone fails #41585

@gjeusel

Description

@gjeusel
  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample

import pandas as pd

kwargs = {"start": "2020-01-01", "tz": "CET", "freq": "1MS", "closed": "left"}

index_one_year = pd.date_range(end="2021-01-01", **kwargs).tz_convert("UTC")
df_one_year = pd.DataFrame(data={"full": [1] * len(index_one_year)}, index=index_one_year)

index_one_month_more = pd.date_range(end="2021-02-01", **kwargs).tz_convert("UTC")
df_one_month_more = pd.DataFrame(
    data={"one_month_more": [1] * len(index_one_month_more)}, index=index_one_month_more
)


pd.concat([df_one_year, df_one_year], axis=1)  # works
pd.concat([df_one_year, df_one_month_more], axis=1)  # raise:
# ValueError: Inferred frequency M from passed values does not conform to passed frequency MS

Problem description

Visualize the two dataframes
                           full
2019-12-31 23:00:00+00:00     1
2020-01-31 23:00:00+00:00     1
2020-02-29 23:00:00+00:00     1
2020-03-31 22:00:00+00:00     1
2020-04-30 22:00:00+00:00     1
2020-05-31 22:00:00+00:00     1
2020-06-30 22:00:00+00:00     1
2020-07-31 22:00:00+00:00     1
2020-08-31 22:00:00+00:00     1
2020-09-30 22:00:00+00:00     1
2020-10-31 23:00:00+00:00     1
2020-11-30 23:00:00+00:00     1
                           one_month_more
2019-12-31 23:00:00+00:00               1
2020-01-31 23:00:00+00:00               1
2020-02-29 23:00:00+00:00               1
2020-03-31 22:00:00+00:00               1
2020-04-30 22:00:00+00:00               1
2020-05-31 22:00:00+00:00               1
2020-06-30 22:00:00+00:00               1
2020-07-31 22:00:00+00:00               1
2020-08-31 22:00:00+00:00               1
2020-09-30 22:00:00+00:00               1
2020-10-31 23:00:00+00:00               1
2020-11-30 23:00:00+00:00               1
2020-12-31 23:00:00+00:00               1

A workaround is to convert dataframes back to the timezone "CET" where the inferred_freq is the correct one.

Still, I would have expected no issues on this concatenation, even when the timezone is UTC.

Expected Output

Output of pd.show_versions()

Details

INSTALLED VERSIONS

commit : 2cb9652
python : 3.9.2.final.0
python-bits : 64
OS : Darwin
OS-release : 20.4.0
Version : Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.2.4
numpy : 1.20.1
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 52.0.0.post20210125
Cython : 0.29.22
pytest : 6.1.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.6 (dt dec pq3 ext lo64)
jinja2 : 2.11.3
IPython : 7.21.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 3.0.0
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.3.23
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
numba : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugFrequencyDateOffsetsReshapingConcat, Merge/Join, Stack/Unstack, ExplodeTimezonesTimezone data dtype

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions