", line 1, in File "/home/tesla/Projects/panda...">

PeriodDType should require freq argument · Issue #27388 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

import pandas as pd pd.PeriodDtype() Traceback (most recent call last): File "", line 1, in File "/home/tesla/Projects/pandas/pandas/core/dtypes/dtypes.py", line 149, in repr return str(self) File "/home/tesla/Projects/pandas/pandas/core/dtypes/dtypes.py", line 880, in str return self.name File "/home/tesla/Projects/pandas/pandas/core/dtypes/dtypes.py", line 884, in name return "period[{freq}]".format(freq=self.freq.freqstr) AttributeError: 'NoneType' object has no attribute 'freqstr'

Problem description

Currently if you instantiate a PeriodDtype it is not required to set the freq since the __new__ method passes a freq=None, which eventually leads to the error shown in the first code snippet.

Having a default None frequency doesn't really make sense. In fact there shouldn't be any default value of frequency. The freq should be a required argument.

Expected Output

import pandas as pd pd.Period pd.Period( pd.PeriodDtype( pd.PeriodIndex( pd.PeriodDtype() Traceback (most recent call last): File "", line 1, in TypeError: new() missing 1 required positional argument: 'freq'

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 269d368
python : 3.7.3.final.0
python-bits : 64
OS : Linux
OS-release : 5.2.0-arch2-1-ARCH
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 0.25.0rc0+62.g269d36814
numpy : 1.16.4
pytz : 2019.1
dateutil : 2.8.0
pip : 19.1.1
setuptools : 41.0.1
Cython : 0.29.11
pytest : 5.0.0
hypothesis : 4.23.6
sphinx : 1.8.5
blosc : None
feather : None
xlsxwriter : 1.1.8
lxml.etree : 4.3.4
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.6.1
pandas_datareader: None
bs4 : 4.7.1
bottleneck : 1.2.1
fastparquet : 0.3.0
gcsfs : None
lxml.etree : 4.3.4
matplotlib : 3.1.0
numexpr : 2.6.9
odfpy : None
openpyxl : 2.6.2
pandas_gbq : None
pyarrow : 0.11.1
pytables : None
s3fs : 0.2.1
scipy : 1.2.1
sqlalchemy : 1.3.5
tables : 3.5.2
xarray : 0.12.1
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : 1.1.8