Skip to content

Period dtype not recognized for added column #26861

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
BeforeFlight opened this issue Jun 14, 2019 · 2 comments · Fixed by #42654
Closed

Period dtype not recognized for added column #26861

BeforeFlight opened this issue Jun 14, 2019 · 2 comments · Fixed by #42654
Labels
Dtype Conversions Unexpected or buggy dtype conversions good first issue Indexing Related to indexing on series/frames, not to indexes themselves Needs Tests Unit test(s) needed to prevent regressions Period Period data type
Milestone

Comments

@BeforeFlight
Copy link
Contributor

data = [pd.Period('2002-03','D')]
# 1
pd.DataFrame({'a': data}).a.dtype
# 2
df = pd.DataFrame([])
df['a'] = data
df.a.dtype
period[D]

dtype('O')

Expected output is the same - period[D]. As it is the same for example for data = [pd.Timestamp('2000-01-01')] : both dtype('<M8[ns]').

INSTALLED VERSIONS

commit: None
python: 3.7.3.final.0
python-bits: 64
OS: Linux
OS-release: 5.0.0-16-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.2
pytest: 4.5.0
pip: 19.1.1
setuptools: 41.0.1
Cython: 0.29.7
numpy: 1.16.4
scipy: 1.2.1
pyarrow: None
xarray: 0.12.1
IPython: 7.2.0
sphinx: None
patsy: None
dateutil: 2.8.0
pytz: 2019.1
blosc: None
bottleneck: None
tables: 3.5.1
numexpr: 2.6.9
feather: None
matplotlib: 3.0.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

@TomAugspurger
Copy link
Contributor

Probably a bug, thought I would recommend being explicit about your dtypes where possible,

df['a'] = pd.array(data)  # or `pd.array(data, dtype=pd.PeriodDtype("d"))`

@TomAugspurger TomAugspurger added the Dtype Conversions Unexpected or buggy dtype conversions label Jun 16, 2019
@TomAugspurger TomAugspurger added this to the Contributions Welcome milestone Jun 16, 2019
@jbrockmendel jbrockmendel added the Period Period data type label Oct 17, 2019
@mroeschke mroeschke added Bug Indexing Related to indexing on series/frames, not to indexes themselves labels May 11, 2020
@jbrockmendel
Copy link
Member

This now works, could use a test

@jbrockmendel jbrockmendel added the Needs Tests Unit test(s) needed to prevent regressions label May 18, 2021
@jreback jreback modified the milestones: Contributions Welcome, 1.4 Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions good first issue Indexing Related to indexing on series/frames, not to indexes themselves Needs Tests Unit test(s) needed to prevent regressions Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants