Skip to content

Commit cf99c9e

Browse files
author
Khor Chean Wei
authored
Merge branch 'main' into groupby_describe_empty_dataset
2 parents 8f421ae + a4338a5 commit cf99c9e

27 files changed

+358
-223
lines changed

.github/workflows/code-checks.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ jobs:
8080
id: build
8181
uses: ./.github/actions/build_pandas
8282

83+
- name: Check for no warnings when building single-page docs
84+
run: ci/code_checks.sh single-docs
85+
if: ${{ steps.build.outcome == 'success' }}
86+
8387
- name: Run checks on imported code
8488
run: ci/code_checks.sh code
8589
if: ${{ steps.build.outcome == 'success' }}

.github/workflows/docbuild-and-upload.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
run: |
3838
source activate pandas-dev
3939
python web/pandas_web.py web/pandas --target-path=web/build
40+
4041
- name: Build documentation
4142
run: |
4243
source activate pandas-dev

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ repos:
2626
types_or: [python, rst, markdown]
2727
files: ^(pandas|doc)/
2828
- repo: https://github.com/pre-commit/pre-commit-hooks
29-
rev: v4.1.0
29+
rev: v4.2.0
3030
hooks:
3131
- id: debug-statements
3232
- id: end-of-file-fixer
@@ -56,7 +56,7 @@ repos:
5656
hooks:
5757
- id: isort
5858
- repo: https://github.com/asottile/pyupgrade
59-
rev: v2.31.1
59+
rev: v2.32.0
6060
hooks:
6161
- id: pyupgrade
6262
args: [--py38-plus]
@@ -71,7 +71,7 @@ repos:
7171
types: [text] # overwrite types: [rst]
7272
types_or: [python, rst]
7373
- repo: https://github.com/sphinx-contrib/sphinx-lint
74-
rev: v0.2
74+
rev: v0.4.1
7575
hooks:
7676
- id: sphinx-lint
7777
- repo: https://github.com/asottile/yesqa

ci/code_checks.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
# $ ./ci/code_checks.sh doctests # run doctests
1313
# $ ./ci/code_checks.sh docstrings # validate docstring errors
1414
# $ ./ci/code_checks.sh typing # run static type analysis
15+
# $ ./ci/code_checks.sh single-docs # check single-page docs build warning-free
1516

16-
[[ -z "$1" || "$1" == "code" || "$1" == "doctests" || "$1" == "docstrings" || "$1" == "typing" ]] || \
17+
[[ -z "$1" || "$1" == "code" || "$1" == "doctests" || "$1" == "docstrings" || "$1" == "typing" || "$1" == "single-docs" ]] || \
1718
{ echo "Unknown command $1. Usage: $0 [code|doctests|docstrings|typing]"; exit 9999; }
1819

1920
BASE_DIR="$(dirname $0)/.."
@@ -102,4 +103,11 @@ if [[ -z "$CHECK" || "$CHECK" == "typing" ]]; then
102103
fi
103104
fi
104105

106+
### SINGLE-PAGE DOCS ###
107+
if [[ -z "$CHECK" || "$CHECK" == "single-docs" ]]; then
108+
python doc/make.py --warnings-are-errors --single pandas.Series.value_counts
109+
python doc/make.py --warnings-are-errors --single pandas.Series.str.split
110+
python doc/make.py clean
111+
fi
112+
105113
exit $RET

doc/source/index.rst.template

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pandas documentation
2626
easy-to-use data structures and data analysis tools for the `Python <https://www.python.org/>`__
2727
programming language.
2828

29+
{% if not single_doc -%}
2930
.. panels::
3031
:card: + intro-card text-center
3132
:column: col-lg-6 col-md-6 col-sm-6 col-xs-12 d-flex
@@ -96,16 +97,22 @@ programming language.
9697
:text: To the development guide
9798
:classes: btn-block btn-secondary stretched-link
9899

99-
100+
{% endif %}
100101
{% if single_doc and single_doc.endswith('.rst') -%}
101102
.. toctree::
102103
:maxdepth: 3
103104
:titlesonly:
104105

105106
{{ single_doc[:-4] }}
107+
{% elif single_doc and single_doc.count('.') <= 1 %}
108+
.. autosummary::
109+
:toctree: reference/api/
110+
111+
{{ single_doc }}
106112
{% elif single_doc %}
107113
.. autosummary::
108114
:toctree: reference/api/
115+
:template: autosummary/accessor_method.rst
109116

110117
{{ single_doc }}
111118
{% else -%}

doc/source/whatsnew/v1.5.0.rst

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,17 @@ The protocol consists of two parts:
3737
Styler
3838
^^^^^^
3939

40-
- New method :meth:`.Styler.to_string` for alternative customisable output methods (:issue:`44502`)
41-
- Added the ability to render ``border`` and ``border-{side}`` CSS properties in Excel (:issue:`42276`)
42-
- Added a new method :meth:`.Styler.concat` which allows adding customised footer rows to visualise additional calculations on the data, e.g. totals and counts etc. (:issue:`43875`, :issue:`46186`)
43-
- :meth:`.Styler.highlight_null` now accepts ``color`` consistently with other builtin methods and deprecates ``null_color`` although this remains backwards compatible (:issue:`45907`)
40+
The most notable development is the new method :meth:`.Styler.concat` which
41+
allows adding customised footer rows to visualise additional calculations on the data,
42+
e.g. totals and counts etc. (:issue:`43875`, :issue:`46186`)
43+
44+
Additionally there is an alternative output method :meth:`.Styler.to_string`,
45+
which allows using the Styler's formatting methods to create, for example, CSVs (:issue:`44502`).
46+
47+
Minor feature improvements are:
48+
49+
- Adding the ability to render ``border`` and ``border-{side}`` CSS properties in Excel (:issue:`42276`)
50+
- Making keyword arguments consist: :meth:`.Styler.highlight_null` now accepts ``color`` and deprecates ``null_color`` although this remains backwards compatible (:issue:`45907`)
4451

4552
.. _whatsnew_150.enhancements.resample_group_keys:
4653

@@ -113,7 +120,7 @@ Other enhancements
113120
- :meth:`DataFrame.reset_index` now accepts a ``names`` argument which renames the index names (:issue:`6878`)
114121
- :meth:`pd.concat` now raises when ``levels`` is given but ``keys`` is None (:issue:`46653`)
115122
- :meth:`pd.concat` now raises when ``levels`` contains duplicate values (:issue:`46653`)
116-
- Added ``numeric_only`` argument to :meth:`DataFrame.corr`, :meth:`DataFrame.corrwith`, and :meth:`DataFrame.cov` (:issue:`46560`)
123+
- Added ``numeric_only`` argument to :meth:`DataFrame.corr`, :meth:`DataFrame.corrwith`, :meth:`DataFrame.cov`, :meth:`DataFrame.idxmin`, :meth:`DataFrame.idxmax`, :meth:`.GroupBy.idxmin`, :meth:`.GroupBy.idxmax`, :meth:`.GroupBy.var`, :meth:`.GroupBy.std`, :meth:`.GroupBy.sem`, and :meth:`.GroupBy.quantile` (:issue:`46560`)
117124
- A :class:`errors.PerformanceWarning` is now thrown when using ``string[pyarrow]`` dtype with methods that don't dispatch to ``pyarrow.compute`` methods (:issue:`42613`, :issue:`46725`)
118125
- Added ``validate`` argument to :meth:`DataFrame.join` (:issue:`46622`)
119126
- A :class:`errors.PerformanceWarning` is now thrown when using ``string[pyarrow]`` dtype with methods that don't dispatch to ``pyarrow.compute`` methods (:issue:`42613`)
@@ -127,13 +134,6 @@ Notable bug fixes
127134

128135
These are bug fixes that might have notable behavior changes.
129136

130-
.. _whatsnew_150.notable_bug_fixes.notable_bug_fix1:
131-
132-
Styler
133-
^^^^^^
134-
135-
- Fixed bug in :class:`CSSToExcelConverter` leading to ``TypeError`` when border color provided without border style for ``xlsxwriter`` engine (:issue:`42276`)
136-
137137
.. _whatsnew_150.notable_bug_fixes.groupby_transform_dropna:
138138

139139
Using ``dropna=True`` with ``groupby`` transforms
@@ -194,13 +194,6 @@ did not have the same index as the input.
194194
df.groupby('a', dropna=True).transform('ffill')
195195
df.groupby('a', dropna=True).transform(lambda x: x)
196196
197-
.. _whatsnew_150.notable_bug_fixes.visualization:
198-
199-
Styler
200-
^^^^^^
201-
202-
- Fix showing "None" as ylabel in :meth:`Series.plot` when not setting ylabel (:issue:`46129`)
203-
204197
.. _whatsnew_150.notable_bug_fixes.notable_bug_fix2:
205198

206199
notable_bug_fix2
@@ -615,6 +608,7 @@ Plotting
615608
- Bug in :meth:`DataFrame.boxplot` that prevented specifying ``vert=False`` (:issue:`36918`)
616609
- Bug in :meth:`DataFrame.plot.scatter` that prevented specifying ``norm`` (:issue:`45809`)
617610
- The function :meth:`DataFrame.plot.scatter` now accepts ``color`` as an alias for ``c`` and ``size`` as an alias for ``s`` for consistency to other plotting functions (:issue:`44670`)
611+
- Fix showing "None" as ylabel in :meth:`Series.plot` when not setting ylabel (:issue:`46129`)
618612

619613
Groupby/resample/rolling
620614
^^^^^^^^^^^^^^^^^^^^^^^^
@@ -660,7 +654,7 @@ ExtensionArray
660654
Styler
661655
^^^^^^
662656
- Bug when attempting to apply styling functions to an empty DataFrame subset (:issue:`45313`)
663-
-
657+
- Bug in :class:`CSSToExcelConverter` leading to ``TypeError`` when border color provided without border style for ``xlsxwriter`` engine (:issue:`42276`)
664658

665659
Metadata
666660
^^^^^^^^

pandas/_libs/tslibs/conversion.pyx

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,8 @@ from pandas._libs.tslibs.np_datetime import (
5252
)
5353

5454
from pandas._libs.tslibs.timezones cimport (
55-
get_dst_info,
5655
get_utcoffset,
57-
is_fixed_offset,
58-
is_tzlocal,
5956
is_utc,
60-
is_zoneinfo,
6157
maybe_get_tz,
6258
tz_compare,
6359
utc_pytz as UTC,
@@ -77,10 +73,7 @@ from pandas._libs.tslibs.nattype cimport (
7773
checknull_with_nat,
7874
)
7975
from pandas._libs.tslibs.tzconversion cimport (
80-
bisect_right_i8,
81-
infer_dateutil_fold,
82-
localize_tzinfo_api,
83-
tz_convert_from_utc_single,
76+
Localizer,
8477
tz_localize_to_utc_single,
8578
)
8679

@@ -518,9 +511,7 @@ cdef _TSObject _create_tsobject_tz_using_offset(npy_datetimestruct dts,
518511
_TSObject obj = _TSObject()
519512
int64_t value # numpy dt64
520513
datetime dt
521-
ndarray[int64_t] trans
522-
int64_t* tdata
523-
int64_t[::1] deltas
514+
Py_ssize_t pos
524515

525516
value = dtstruct_to_dt64(&dts)
526517
obj.dts = dts
@@ -530,19 +521,18 @@ cdef _TSObject _create_tsobject_tz_using_offset(npy_datetimestruct dts,
530521
check_overflows(obj)
531522
return obj
532523

524+
cdef:
525+
Localizer info = Localizer(tz)
526+
533527
# Infer fold from offset-adjusted obj.value
534528
# see PEP 495 https://www.python.org/dev/peps/pep-0495/#the-fold-attribute
535-
if is_utc(tz):
529+
if info.use_utc:
536530
pass
537-
elif is_tzlocal(tz) or is_zoneinfo(tz):
538-
localize_tzinfo_api(obj.value, tz, &obj.fold)
539-
else:
540-
trans, deltas, typ = get_dst_info(tz)
541-
542-
if typ == 'dateutil':
543-
tdata = <int64_t*>cnp.PyArray_DATA(trans)
544-
pos = bisect_right_i8(tdata, obj.value, trans.shape[0]) - 1
545-
obj.fold = infer_dateutil_fold(obj.value, trans, deltas, pos)
531+
elif info.use_tzlocal:
532+
info.utc_val_to_local_val(obj.value, &pos, &obj.fold)
533+
elif info.use_dst and not info.use_pytz:
534+
# i.e. dateutil
535+
info.utc_val_to_local_val(obj.value, &pos, &obj.fold)
546536

547537
# Keep the converter same as PyDateTime's
548538
dt = datetime(obj.dts.year, obj.dts.month, obj.dts.day,
@@ -700,18 +690,19 @@ cdef inline void _localize_tso(_TSObject obj, tzinfo tz):
700690
cdef:
701691
int64_t local_val
702692
Py_ssize_t outpos = -1
693+
Localizer info = Localizer(tz)
703694

704695
assert obj.tzinfo is None
705696

706-
if is_utc(tz):
697+
if info.use_utc:
707698
pass
708699
elif obj.value == NPY_NAT:
709700
pass
710701
else:
711-
local_val = tz_convert_from_utc_single(obj.value, tz, &obj.fold, &outpos)
702+
local_val = info.utc_val_to_local_val(obj.value, &outpos, &obj.fold)
712703

713-
if outpos != -1:
714-
# infer we went through a pytz path
704+
if info.use_pytz:
705+
# infer we went through a pytz path, will have outpos!=-1
715706
tz = tz._tzinfos[tz._transition_info[outpos]]
716707

717708
dt64_to_dtstruct(local_val, &obj.dts)

pandas/_libs/tslibs/timestamps.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,14 @@ class Timestamp(datetime):
199199
@property
200200
def day_of_week(self) -> int: ...
201201
@property
202+
def dayofweek(self) -> int: ...
203+
@property
202204
def day_of_month(self) -> int: ...
203205
@property
204206
def day_of_year(self) -> int: ...
205207
@property
208+
def dayofyear(self) -> int: ...
209+
@property
206210
def quarter(self) -> int: ...
207211
@property
208212
def week(self) -> int: ...
@@ -211,3 +215,7 @@ class Timestamp(datetime):
211215
) -> np.datetime64: ...
212216
@property
213217
def _date_repr(self) -> str: ...
218+
@property
219+
def days_in_month(self) -> int: ...
220+
@property
221+
def daysinmonth(self) -> int: ...

pandas/_libs/tslibs/tzconversion.pxd

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from cpython.datetime cimport tzinfo
22
from numpy cimport (
33
int64_t,
44
intp_t,
5+
ndarray,
56
)
67

78

@@ -21,5 +22,23 @@ cdef bint infer_dateutil_fold(
2122
int64_t value,
2223
const int64_t[::1] trans,
2324
const int64_t[::1] deltas,
24-
intp_t pos,
25+
Py_ssize_t pos,
2526
)
27+
28+
29+
cdef class Localizer:
30+
cdef:
31+
tzinfo tz
32+
bint use_utc, use_fixed, use_tzlocal, use_dst, use_pytz
33+
ndarray trans
34+
Py_ssize_t ntrans
35+
const int64_t[::1] deltas
36+
int64_t delta
37+
int64_t* tdata
38+
39+
cdef inline int64_t utc_val_to_local_val(
40+
self,
41+
int64_t utc_val,
42+
Py_ssize_t* pos,
43+
bint* fold=?,
44+
) except? -1

0 commit comments

Comments
 (0)