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

Pandas datetime64 series no longer has map function when localized #12473

Closed
AlJohri opened this issue Feb 26, 2016 · 2 comments
Closed

Pandas datetime64 series no longer has map function when localized #12473

AlJohri opened this issue Feb 26, 2016 · 2 comments
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Milestone

Comments

@AlJohri
Copy link

AlJohri commented Feb 26, 2016

Create test DF.

df = pd.DataFrame({"uuid": [0,1,2,3,4], "publication_timestamp": ["2015-07-28 00:10:05.852", "2015-10-03 00:17:43.000", "2015-08-20 01:15:52.693", "2015-09-09 00:02:03.083", "2015-12-08 00:02:41.390"], "timezone": ["US/Central", "US/Eastern", "US/Eastern", "US/Pacific", "US/Mountain"]}).set_index('uuid')
                publication_timestamp     timezone
uuid
0    2015-07-28 04:10:05.852000+00:00   US/Central
1           2015-10-03 04:17:43+00:00   US/Eastern
2    2015-08-20 05:15:52.693000+00:00   US/Eastern
3    2015-09-09 04:02:03.083000+00:00   US/Pacific
4    2015-12-08 05:02:41.390000+00:00  US/Mountain

This call to map works fine:

df.publication_timestamp.map(lambda x: x) # works fine

Localizing the datetime64 causes it to no longer have the map function

df['publication_timestamp'] = df.publication_timestamp.astype("datetime64[ms]").dt.tz_localize("UTC")

Doesn't work:

df.publication_timestamp.map(lambda x: x) # no longer works

Error Message

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-13-ba941613799a> in <module>()
----> 1 df.publication_timestamp.map(lambda x: x)

/Users/johria/.pyenv/versions/3.5.1/lib/python3.5/site-packages/pandas/core/series.py in map(self, arg, na_action)
   2052                                      index=self.index).__finalize__(self)
   2053         else:
-> 2054             mapped = map_f(values, arg)
   2055             return self._constructor(mapped,
   2056                                      index=self.index).__finalize__(self)

TypeError: Argument 'arr' has incorrect type (expected numpy.ndarray, got DatetimeIndex)

output of pd.show_versions()


INSTALLED VERSIONS
------------------
commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Darwin
OS-release: 15.0.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.17.1
nose: 1.3.7
pip: 8.0.3
setuptools: 19.4
Cython: None
numpy: 1.10.4
scipy: 0.17.0
statsmodels: 0.6.1
IPython: 4.1.1
sphinx: 1.3.5
patsy: 0.4.1
dateutil: 2.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.5.1
openpyxl: 2.2.0-b1
xlrd: 0.9.4
xlwt: None
xlsxwriter: None
lxml: 3.5.0
bs4: 4.4.1
html5lib: None
httplib2: 0.9.2
apiclient: 1.4.2
sqlalchemy: 1.0.11
pymysql: None
psycopg2: None
Jinja2: 2.8
@sinhrks
Copy link
Member

sinhrks commented Feb 27, 2016

Thanks for the report. It looks a bug when dtype._values doesn't return ndarray. PR is appreciated.

s = pd.Series(pd.date_range('2011-01-01', '2011-01-02', freq='H').tz_localize('US/Eastern'))
s.dtype
# datetime64[ns, US/Eastern]

s.map(lambda x: x)
# TypeError: Argument 'arr' has incorrect type (expected numpy.ndarray, got DatetimeIndex)
s = pd.Series([1, 1, 2, 3], dtype='category')
s.dtype
# category

s.map(lambda x: x)
# TypeError: Argument 'arr' has incorrect type (expected numpy.ndarray, got Categorical)

@sinhrks sinhrks added Bug Dtype Conversions Unexpected or buggy dtype conversions labels Feb 27, 2016
@jreback
Copy link
Contributor

jreback commented Feb 27, 2016

similar to #11757

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants