Skip to content

BUG: cut and qcut do not retain timezone information #19872

Closed
@jschendel

Description

@jschendel

Code Sample, a copy-pastable example if possible

Setup:

In [2]: s = pd.Series(pd.date_range('20180101', periods=3, tz='US/Eastern'))

In [3]: s
Out[3]:
0   2018-01-01 00:00:00-05:00
1   2018-01-02 00:00:00-05:00
2   2018-01-03 00:00:00-05:00
dtype: datetime64[ns, US/Eastern]

Timezone information is lost after using cut:

In [4]: pd.cut(s, 2)
Out[4]:
0    (2018-01-01 04:57:07.200000, 2018-01-02 05:00:00]
1    (2018-01-01 04:57:07.200000, 2018-01-02 05:00:00]
2           (2018-01-02 05:00:00, 2018-01-03 05:00:00]
dtype: category
Categories (2, interval[datetime64[ns]]): [ <
                                           (2018-01-01 04:57:07.200000, 2018-01-02 05:00:00] <
                                           (2018-01-02 05:00:00, 2018-01-03 05:00:00]]

Timezone information is lost after using qcut:

In [5]: pd.qcut(s, 2)
Out[5]:
0    (2018-01-01 04:59:59.999999999, 2018-01-02 05:...
1    (2018-01-01 04:59:59.999999999, 2018-01-02 05:...
2           (2018-01-02 05:00:00, 2018-01-03 05:00:00]
dtype: category
Categories (2, interval[datetime64[ns]]): [ <
                                           (2018-01-01 04:59:59.999999999, 2018-01-02 05:0... <
                                           (2018-01-02 05:00:00, 2018-01-03 05:00:00]]

Problem description

Timezone information is lost after using cut and qcut.

Expected Output

I'd except cut and qcut to retain timezone information.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: ce77b79
python: 3.6.1.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.23.0.dev0+364.gce77b79
pytest: 3.1.2
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.13.3
scipy: 1.0.0
pyarrow: 0.6.0
xarray: 0.9.6
IPython: 6.1.0
sphinx: 1.5.6
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: 3.4.2
numexpr: 2.6.4
feather: 0.4.0
matplotlib: 2.0.2
openpyxl: 2.4.8
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 0.9.8
lxml: 3.8.0
bs4: None
html5lib: 0.999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: 0.1.0
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions