Skip to content

Cannot map Timestamp.isocalendar on tz-aware timestamp series, gives ValueError: MultiIndex has no single backing array #28092

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
alexmojaki opened this issue Aug 22, 2019 · 2 comments
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays.

Comments

@alexmojaki
Copy link
Contributor

Problem description

While:

pd.to_datetime(dates).map(pd.Timestamp.isocalendar)

works as expected,

pd.to_datetime(dates, utc=True).map(pd.Timestamp.isocalendar)

(i.e. just adding utc=True)

or any variation of it using map fails with the below error. Only a list comprehension works, so it doesn't seem possible to vectorize the operation. The error message is also confusing.

Example code

import pandas as pd

pd.show_versions()

dates = pd.Series(pd.date_range(start='20180101', end='20180102', periods=2))
print(dates)
print(pd.to_datetime(dates).map(pd.Timestamp.isocalendar))
print([x.isocalendar() for x in pd.to_datetime(dates, utc=True)])

# Error here
print(pd.to_datetime(dates, utc=True).map(lambda x:x.isocalendar()))

Try it here: https://repl.it/repls/RawClosedPorts

Output:

0   2018-01-01
1   2018-01-02
dtype: datetime64[ns]
0    (2018, 1, 1)
1    (2018, 1, 2)
dtype: object
[(2018, 1, 1), (2018, 1, 2)]
Traceback (most recent call last):
  File "main.py", line 9, in <module>
    print(pd.to_datetime(dates, utc=True).map(lambda x:x.isocalendar()))
  File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/pandas/core/series.py", line 3821, in map
    new_values = super()._map_values(arg, na_action=na_action)
  File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/pandas/core/base.py", line 1300, in _map_values
    new_values = map_f(values, mapper)
  File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/pandas/core/base.py", line 1287, in <lambda>
    map_f = lambda values, f: values.map(f)
  File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/pandas/core/arrays/datetimelike.py", line 722, in map
    return Index(self).map(mapper).array
  File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/pandas/core/indexes/multi.py", line 633, in array
    raise ValueError(msg)
ValueError: MultiIndex has no single backing array. Use 'MultiIndex.to_numpy()' to get a NumPy array of tuples.

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit           : None
python           : 3.7.4.final.0
python-bits      : 64
OS               : Linux
OS-release       : 4.15.0-1036-gcp
machine          : x86_64
processor        :
byteorder        : little
LC_ALL           : None
LANG             : C.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 0.25.0
numpy            : 1.17.0
pytz             : 2019.2
dateutil         : 2.8.0
pip              : 19.0.3
setuptools       : 40.8.0
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
fastparquet      : None
gcsfs            : None
lxml.etree       : None
matplotlib       : 3.1.1
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pytables         : None
s3fs             : None
scipy            : 1.3.0
sqlalchemy       : None
tables           : None
xarray           : None
xlrd             : None
xlwt             : None
xlsxwriter       : None
@mroeschke
Copy link
Member

Guessing this is bug will impact all ExtensionArrays.

@mroeschke mroeschke added Bug ExtensionArray Extending pandas with custom dtypes or arrays. labels Aug 22, 2019
@mroeschke
Copy link
Member

Actually #23179 is the blocker for this feature. Closing as a dup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays.
Projects
None yet
Development

No branches or pull requests

2 participants