Skip to content
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

BUG: .dt.isocalendar().week returns unexpected dtype (UInt32) #42429

Closed
2 of 3 tasks
outa opened this issue Jul 7, 2021 · 2 comments
Closed
2 of 3 tasks

BUG: .dt.isocalendar().week returns unexpected dtype (UInt32) #42429

outa opened this issue Jul 7, 2021 · 2 comments
Labels
Bug Datetime Datetime data dtype Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@outa
Copy link

outa commented Jul 7, 2021

  • 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.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

data = {'date': pd.date_range('2021-07-01', freq='D', periods=7)}
df = pd.DataFrame(data)

weeknumbers = df.date.dt.isocalendar().week

weeknumbers
0    26
1    26
2    26
3    26
4    27
5    27
6    27
Name: week, dtype: UInt32

Problem description

This returns dtype UInt32, with weeknumbers.values being an "IntegerArray" from pandas.

I am not sure if this is intended, but I discovered this because I replaced the deprecated dt.weekofyear with dt.isocalendar().week and then had weeknumbers.values.tolist() at a later point in my code which results in an AttributeError.

Expected Output

I would have expected the dtype to be int64, or, more importanty, the the .values being a numpy array, so that .values.tolist() works as expected.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f00ed8f
python : 3.9.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.8.0-59-generic
Version : #66-Ubuntu SMP Thu Jun 17 00:46:01 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : de_DE.UTF-8
LOCALE : de_DE.UTF-8

pandas : 1.3.0
numpy : 1.21.0
pytz : 2021.1
dateutil : 2.8.1
pip : 21.1.3
setuptools : 52.0.0.post20210125
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
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 : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@outa outa added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 7, 2021
@rhshadrach rhshadrach added the Datetime Datetime data dtype label Jul 9, 2021
@rhshadrach
Copy link
Member

This was indeed intentional, e.g #33220 (comment). As with any pandas Series, you can directly call tolist without accessing the underlying array:

df.date.dt.isocalendar().week.tolist()

Does this satisfy your use-case?

@outa
Copy link
Author

outa commented Jul 9, 2021

Yes it does. Thanks for the clarification!

@outa outa closed this as completed Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants