From 286f7f5906035453b1a780774e7808f74cbd8fb6 Mon Sep 17 00:00:00 2001 From: Thomas Li <47963215+lithomas1@users.noreply.github.com> Date: Wed, 24 May 2023 11:06:08 -0700 Subject: [PATCH] BUG: Period.now not taking kwargs --- doc/source/whatsnew/v2.1.0.rst | 1 + pandas/_libs/meson.build | 2 +- pandas/_libs/tslibs/meson.build | 2 +- pandas/_libs/window/meson.build | 2 ++ pandas/tests/scalar/period/test_period.py | 6 ++++-- setup.py | 2 +- 6 files changed, 10 insertions(+), 5 deletions(-) diff --git a/doc/source/whatsnew/v2.1.0.rst b/doc/source/whatsnew/v2.1.0.rst index 11533647ca124..8f994edbd9e4d 100644 --- a/doc/source/whatsnew/v2.1.0.rst +++ b/doc/source/whatsnew/v2.1.0.rst @@ -405,6 +405,7 @@ Period - Bug in :class:`PeriodDtype` constructor raising ``ValueError`` instead of ``TypeError`` when an invalid type is passed (:issue:`51790`) - Bug in :func:`read_csv` not processing empty strings as a null value, with ``engine="pyarrow"`` (:issue:`52087`) - Bug in :func:`read_csv` returning ``object`` dtype columns instead of ``float64`` dtype columns with ``engine="pyarrow"`` for columns that are all null with ``engine="pyarrow"`` (:issue:`52087`) +- Bug in :meth:`Period.now` not accepting the ``freq`` parameter as a keyword argument (:issue:`53369`) - Bug in :meth:`arrays.PeriodArray.map` and :meth:`PeriodIndex.map`, where the supplied callable operated array-wise instead of element-wise (:issue:`51977`) - Bug in incorrectly allowing construction of :class:`Period` or :class:`PeriodDtype` with :class:`CustomBusinessDay` freq; use :class:`BusinessDay` instead (:issue:`52534`) diff --git a/pandas/_libs/meson.build b/pandas/_libs/meson.build index 382247c63c1ad..32db8179d1280 100644 --- a/pandas/_libs/meson.build +++ b/pandas/_libs/meson.build @@ -117,7 +117,7 @@ foreach ext_name, ext_dict : libs_sources py.extension_module( ext_name, ext_dict.get('sources'), - cython_args: ['--include-dir', meson.current_build_dir()], + cython_args: ['--include-dir', meson.current_build_dir(), '-X always_allow_keywords=true'], include_directories: [inc_np] + ext_dict.get('include_dirs', ''), dependencies: ext_dict.get('deps', ''), subdir: 'pandas/_libs', diff --git a/pandas/_libs/tslibs/meson.build b/pandas/_libs/tslibs/meson.build index fc8c9e609c416..bc691ab8ca86b 100644 --- a/pandas/_libs/tslibs/meson.build +++ b/pandas/_libs/tslibs/meson.build @@ -34,7 +34,7 @@ foreach ext_name, ext_dict : tslibs_sources py.extension_module( ext_name, ext_dict.get('sources'), - cython_args: ['--include-dir', meson.current_build_dir()], + cython_args: ['--include-dir', meson.current_build_dir(), '-X always_allow_keywords=true'], include_directories: [inc_np] + ext_dict.get('include_dirs', ''), dependencies: ext_dict.get('deps', ''), subdir: 'pandas/_libs/tslibs', diff --git a/pandas/_libs/window/meson.build b/pandas/_libs/window/meson.build index 7d7c34a57c6a6..d6059f8bbcc2b 100644 --- a/pandas/_libs/window/meson.build +++ b/pandas/_libs/window/meson.build @@ -1,6 +1,7 @@ py.extension_module( 'aggregations', ['aggregations.pyx'], + cython_args: ['-X always_allow_keywords=true'], include_directories: [inc_np, '../src'], dependencies: [py_dep], subdir: 'pandas/_libs/window', @@ -11,6 +12,7 @@ py.extension_module( py.extension_module( 'indexers', ['indexers.pyx'], + cython_args: ['-X always_allow_keywords=true'], include_directories: [inc_np], dependencies: [py_dep], subdir: 'pandas/_libs/window', diff --git a/pandas/tests/scalar/period/test_period.py b/pandas/tests/scalar/period/test_period.py index d908c641a30c6..1e8c2bce1d90d 100644 --- a/pandas/tests/scalar/period/test_period.py +++ b/pandas/tests/scalar/period/test_period.py @@ -72,14 +72,16 @@ def test_construction(self): assert i1 != i4 assert i4 == i5 - i1 = Period.now("Q") + i1 = Period.now(freq="Q") i2 = Period(datetime.now(), freq="Q") i3 = Period.now("q") assert i1 == i2 assert i1 == i3 - i1 = Period.now("D") + # Pass in freq as a keyword argument sometimes as a test for + # https://github.com/pandas-dev/pandas/issues/53369 + i1 = Period.now(freq="D") i2 = Period(datetime.now(), freq="D") i3 = Period.now(offsets.Day()) diff --git a/setup.py b/setup.py index ee444f1aaeb85..87c45f2bac6f6 100755 --- a/setup.py +++ b/setup.py @@ -378,7 +378,7 @@ def run(self): # Note: if not using `cythonize`, coverage can be enabled by # pinning `ext.cython_directives = directives` to each ext in extensions. # github.com/cython/cython/wiki/enhancements-compilerdirectives#in-setuppy -directives = {"linetrace": False, "language_level": 3} +directives = {"linetrace": False, "language_level": 3, "always_allow_keywords": True} macros = [] if linetrace: # https://pypkg.com/pypi/pytest-cython/f/tests/example-project/setup.py