Skip to content

Commit c5bd91c

Browse files
authored
Merge branch 'main' into issue2
2 parents ca04f1f + 2eca7e1 commit c5bd91c

40 files changed

+620
-73
lines changed

.github/workflows/32-bit-linux.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ on:
1212
paths-ignore:
1313
- "doc/**"
1414

15+
permissions:
16+
contents: read
17+
1518
jobs:
1619
pytest:
1720
runs-on: ubuntu-latest

.github/workflows/assign.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ on:
33
issue_comment:
44
types: created
55

6+
permissions:
7+
contents: read
8+
69
jobs:
710
issue_assign:
11+
permissions:
12+
issues: write
13+
pull-requests: write
814
runs-on: ubuntu-latest
915
steps:
1016
- if: github.event.comment.body == 'take'

.github/workflows/asv-bot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ env:
99
ENV_FILE: environment.yml
1010
COMMENT: ${{github.event.comment.body}}
1111

12+
permissions:
13+
contents: read
14+
1215
jobs:
1316
autotune:
17+
permissions:
18+
contents: read
19+
issues: write
20+
pull-requests: write
1421
name: "Run benchmarks"
1522
# TODO: Support more benchmarking options later, against different branches, against self, etc
1623
if: startsWith(github.event.comment.body, '@github-actions benchmark')

.github/workflows/autoupdate-pre-commit-config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ on:
55
- cron: "0 7 1 * *" # At 07:00 on 1st of every month.
66
workflow_dispatch:
77

8+
permissions:
9+
contents: read
10+
811
jobs:
912
update-pre-commit:
13+
permissions:
14+
contents: write # for technote-space/create-pr-action to push code
15+
pull-requests: write # for technote-space/create-pr-action to create a PR
1016
if: github.repository_owner == 'pandas-dev'
1117
name: Autoupdate pre-commit config
1218
runs-on: ubuntu-latest

.github/workflows/code-checks.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ env:
1414
ENV_FILE: environment.yml
1515
PANDAS_CI: 1
1616

17+
permissions:
18+
contents: read
19+
1720
jobs:
1821
pre_commit:
1922
name: pre-commit

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ env:
1414
ENV_FILE: environment.yml
1515
PANDAS_CI: 1
1616

17+
permissions:
18+
contents: read
19+
1720
jobs:
1821
web_and_docs:
1922
name: Doc Build and Upload

.github/workflows/macos-windows.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ env:
1818
PATTERN: "not slow and not db and not network and not single_cpu"
1919

2020

21+
permissions:
22+
contents: read
23+
2124
jobs:
2225
pytest:
2326
defaults:

.github/workflows/python-dev.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ env:
2727
COVERAGE: true
2828
PYTEST_TARGET: pandas
2929

30+
permissions:
31+
contents: read
32+
3033
jobs:
3134
build:
3235
if: false # Comment this line out to "unfreeze"

.github/workflows/sdist.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ on:
1313
paths-ignore:
1414
- "doc/**"
1515

16+
permissions:
17+
contents: read
18+
1619
jobs:
1720
build:
1821
if: ${{ github.event.label.name == 'Build' || contains(github.event.pull_request.labels.*.name, 'Build') || github.event_name == 'push'}}

.github/workflows/stale-pr.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ on:
44
# * is a special character in YAML so you have to quote this string
55
- cron: "0 0 * * *"
66

7+
permissions:
8+
contents: read
9+
710
jobs:
811
stale:
12+
permissions:
13+
pull-requests: write
914
runs-on: ubuntu-latest
1015
steps:
1116
- uses: actions/stale@v4

.github/workflows/ubuntu.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ on:
1515
env:
1616
PANDAS_CI: 1
1717

18+
permissions:
19+
contents: read
20+
1821
jobs:
1922
pytest:
2023
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ repos:
9393
types: [python]
9494
stages: [manual]
9595
additional_dependencies: &pyright_dependencies
96-
- pyright@1.1.253
96+
- pyright@1.1.258
9797
- repo: local
9898
hooks:
9999
- id: pyright_reportGeneralTypeIssues

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,4 @@ Or maybe through using pandas you have an idea of your own or are looking for so
169169

170170
Feel free to ask questions on the [mailing list](https://groups.google.com/forum/?fromgroups#!forum/pydata) or on [Gitter](https://gitter.im/pydata/pandas).
171171

172-
As contributors and maintainers to this project, you are expected to abide by pandas' code of conduct. More information can be found at: [Contributor Code of Conduct](https://github.com/pandas-dev/pandas/blob/main/.github/CODE_OF_CONDUCT.md)
172+
As contributors and maintainers to this project, you are expected to abide by pandas' code of conduct. More information can be found at: [Contributor Code of Conduct](https://github.com/pandas-dev/.github/blob/master/CODE_OF_CONDUCT.md)

doc/source/reference/testing.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ Exceptions and warnings
2626

2727
errors.AbstractMethodError
2828
errors.AccessorRegistrationWarning
29+
errors.AttributeConflictWarning
30+
errors.ClosedFileError
2931
errors.CSSWarning
3032
errors.DataError
3133
errors.DtypeWarning
3234
errors.DuplicateLabelError
3335
errors.EmptyDataError
36+
errors.IncompatibilityWarning
3437
errors.IndexingError
3538
errors.InvalidIndexError
3639
errors.IntCastingNaNError
@@ -44,6 +47,7 @@ Exceptions and warnings
4447
errors.ParserError
4548
errors.ParserWarning
4649
errors.PerformanceWarning
50+
errors.PossibleDataLossError
4751
errors.PyperclipException
4852
errors.PyperclipWindowsException
4953
errors.SettingWithCopyError

doc/source/whatsnew/v1.5.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,8 @@ Groupby/resample/rolling
10011001
- Bug in :meth:`.DataFrameGroupBy.describe` and :meth:`.SeriesGroupBy.describe` produces inconsistent results for empty datasets (:issue:`41575`)
10021002
- Bug in :meth:`DataFrame.resample` reduction methods when used with ``on`` would attempt to aggregate the provided column (:issue:`47079`)
10031003
- Bug in :meth:`DataFrame.groupby` and :meth:`Series.groupby` would not respect ``dropna=False`` when the input DataFrame/Series had a NaN values in a :class:`MultiIndex` (:issue:`46783`)
1004+
- Bug in :meth:`DataFrameGroupBy.resample` raises ``KeyError`` when getting the result from a key list which misses the resample key (:issue:`47362`)
1005+
-
10041006

10051007
Reshaping
10061008
^^^^^^^^^

pandas/core/arrays/datetimelike.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
from pandas.util._exceptions import find_stack_level
7474

7575
from pandas.core.dtypes.common import (
76-
DT64NS_DTYPE,
7776
is_all_strings,
7877
is_categorical_dtype,
7978
is_datetime64_any_dtype,
@@ -1103,6 +1102,7 @@ def _add_datetimelike_scalar(self, other) -> DatetimeArray:
11031102
self = cast("TimedeltaArray", self)
11041103

11051104
from pandas.core.arrays import DatetimeArray
1105+
from pandas.core.arrays.datetimes import tz_to_dtype
11061106

11071107
assert other is not NaT
11081108
other = Timestamp(other)
@@ -1113,10 +1113,17 @@ def _add_datetimelike_scalar(self, other) -> DatetimeArray:
11131113
# Preserve our resolution
11141114
return DatetimeArray._simple_new(result, dtype=result.dtype)
11151115

1116+
if self._reso != other._reso:
1117+
raise NotImplementedError(
1118+
"Addition between TimedeltaArray and Timestamp with mis-matched "
1119+
"resolutions is not yet supported."
1120+
)
1121+
11161122
i8 = self.asi8
11171123
result = checked_add_with_arr(i8, other.value, arr_mask=self._isnan)
1118-
dtype = DatetimeTZDtype(tz=other.tz) if other.tz else DT64NS_DTYPE
1119-
return DatetimeArray(result, dtype=dtype, freq=self.freq)
1124+
dtype = tz_to_dtype(tz=other.tz, unit=self._unit)
1125+
res_values = result.view(f"M8[{self._unit}]")
1126+
return DatetimeArray._simple_new(res_values, dtype=dtype, freq=self.freq)
11201127

11211128
@final
11221129
def _add_datetime_arraylike(self, other) -> DatetimeArray:

pandas/core/arrays/datetimes.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,23 @@
9191
_midnight = time(0, 0)
9292

9393

94-
def tz_to_dtype(tz):
94+
def tz_to_dtype(tz: tzinfo | None, unit: str = "ns"):
9595
"""
9696
Return a datetime64[ns] dtype appropriate for the given timezone.
9797
9898
Parameters
9999
----------
100100
tz : tzinfo or None
101+
unit : str, default "ns"
101102
102103
Returns
103104
-------
104105
np.dtype or Datetime64TZDType
105106
"""
106107
if tz is None:
107-
return DT64NS_DTYPE
108+
return np.dtype(f"M8[{unit}]")
108109
else:
109-
return DatetimeTZDtype(tz=tz)
110+
return DatetimeTZDtype(tz=tz, unit=unit)
110111

111112

112113
def _field_accessor(name: str, field: str, docstring=None):
@@ -800,7 +801,7 @@ def tz_convert(self, tz) -> DatetimeArray:
800801
)
801802

802803
# No conversion since timestamps are all UTC to begin with
803-
dtype = tz_to_dtype(tz)
804+
dtype = tz_to_dtype(tz, unit=self._unit)
804805
return self._simple_new(self._ndarray, dtype=dtype, freq=self.freq)
805806

806807
@dtl.ravel_compat
@@ -965,10 +966,14 @@ def tz_localize(self, tz, ambiguous="raise", nonexistent="raise") -> DatetimeArr
965966
# Convert to UTC
966967

967968
new_dates = tzconversion.tz_localize_to_utc(
968-
self.asi8, tz, ambiguous=ambiguous, nonexistent=nonexistent
969+
self.asi8,
970+
tz,
971+
ambiguous=ambiguous,
972+
nonexistent=nonexistent,
973+
reso=self._reso,
969974
)
970-
new_dates = new_dates.view(DT64NS_DTYPE)
971-
dtype = tz_to_dtype(tz)
975+
new_dates = new_dates.view(f"M8[{self._unit}]")
976+
dtype = tz_to_dtype(tz, unit=self._unit)
972977

973978
freq = None
974979
if timezones.is_utc(tz) or (len(self) == 1 and not isna(new_dates[0])):

pandas/core/arrays/timedeltas.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def __mul__(self, other) -> TimedeltaArray:
398398
freq = None
399399
if self.freq is not None and not isna(other):
400400
freq = self.freq * other
401-
return type(self)(result, freq=freq)
401+
return type(self)._simple_new(result, dtype=result.dtype, freq=freq)
402402

403403
if not hasattr(other, "dtype"):
404404
# list, tuple
@@ -412,13 +412,14 @@ def __mul__(self, other) -> TimedeltaArray:
412412
# this multiplication will succeed only if all elements of other
413413
# are int or float scalars, so we will end up with
414414
# timedelta64[ns]-dtyped result
415-
result = [self[n] * other[n] for n in range(len(self))]
415+
arr = self._ndarray
416+
result = [arr[n] * other[n] for n in range(len(self))]
416417
result = np.array(result)
417-
return type(self)(result)
418+
return type(self)._simple_new(result, dtype=result.dtype)
418419

419420
# numpy will accept float or int dtype, raise TypeError for others
420421
result = self._ndarray * other
421-
return type(self)(result)
422+
return type(self)._simple_new(result, dtype=result.dtype)
422423

423424
__rmul__ = __mul__
424425

@@ -446,7 +447,8 @@ def __truediv__(self, other):
446447
if self.freq is not None:
447448
# Tick division is not implemented, so operate on Timedelta
448449
freq = self.freq.delta / other
449-
return type(self)(result, freq=freq)
450+
freq = to_offset(freq)
451+
return type(self)._simple_new(result, dtype=result.dtype, freq=freq)
450452

451453
if not hasattr(other, "dtype"):
452454
# e.g. list, tuple
@@ -462,6 +464,7 @@ def __truediv__(self, other):
462464
elif is_object_dtype(other.dtype):
463465
# We operate on raveled arrays to avoid problems in inference
464466
# on NaT
467+
# TODO: tests with non-nano
465468
srav = self.ravel()
466469
orav = other.ravel()
467470
result_list = [srav[n] / orav[n] for n in range(len(srav))]
@@ -488,7 +491,7 @@ def __truediv__(self, other):
488491

489492
else:
490493
result = self._ndarray / other
491-
return type(self)(result)
494+
return type(self)._simple_new(result, dtype=result.dtype)
492495

493496
@unpack_zerodim_and_defer("__rtruediv__")
494497
def __rtruediv__(self, other):

pandas/core/indexes/base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,12 @@ def _outer_indexer(
404404
# associated code in pandas 2.0.
405405
_is_backward_compat_public_numeric_index: bool = False
406406

407-
_engine_type: type[libindex.IndexEngine] | type[
408-
libindex.ExtensionEngine
409-
] = libindex.ObjectEngine
407+
@property
408+
def _engine_type(
409+
self,
410+
) -> type[libindex.IndexEngine] | type[libindex.ExtensionEngine]:
411+
return libindex.ObjectEngine
412+
410413
# whether we support partial string indexing. Overridden
411414
# in DatetimeIndex and PeriodIndex
412415
_supports_partial_string_indexing = False

pandas/core/indexes/category.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def _should_fallback_to_positional(self) -> bool:
192192
_values: Categorical
193193

194194
@property
195-
def _engine_type(self):
195+
def _engine_type(self) -> type[libindex.IndexEngine]:
196196
# self.codes can have dtype int8, int16, int32 or int64, so we need
197197
# to return the corresponding engine type (libindex.Int8Engine, etc.).
198198
return {

pandas/core/indexes/datetimes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,12 @@ class DatetimeIndex(DatetimeTimedeltaMixin):
252252
_typ = "datetimeindex"
253253

254254
_data_cls = DatetimeArray
255-
_engine_type = libindex.DatetimeEngine
256255
_supports_partial_string_indexing = True
257256

257+
@property
258+
def _engine_type(self) -> type[libindex.DatetimeEngine]:
259+
return libindex.DatetimeEngine
260+
258261
_data: DatetimeArray
259262
inferred_freq: str | None
260263
tz: tzinfo | None

pandas/core/indexes/numeric.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class NumericIndex(Index):
106106
}
107107

108108
@property
109-
def _engine_type(self):
109+
def _engine_type(self) -> type[libindex.IndexEngine]:
110110
# error: Invalid index type "Union[dtype[Any], ExtensionDtype]" for
111111
# "Dict[dtype[Any], Type[IndexEngine]]"; expected type "dtype[Any]"
112112
return self._engine_types[self.dtype] # type: ignore[index]
@@ -373,10 +373,13 @@ class Int64Index(IntegerIndex):
373373
__doc__ = _num_index_shared_docs["class_descr"] % _index_descr_args
374374

375375
_typ = "int64index"
376-
_engine_type = libindex.Int64Engine
377376
_default_dtype = np.dtype(np.int64)
378377
_dtype_validation_metadata = (is_signed_integer_dtype, "signed integer")
379378

379+
@property
380+
def _engine_type(self) -> type[libindex.Int64Engine]:
381+
return libindex.Int64Engine
382+
380383

381384
class UInt64Index(IntegerIndex):
382385
_index_descr_args = {
@@ -388,10 +391,13 @@ class UInt64Index(IntegerIndex):
388391
__doc__ = _num_index_shared_docs["class_descr"] % _index_descr_args
389392

390393
_typ = "uint64index"
391-
_engine_type = libindex.UInt64Engine
392394
_default_dtype = np.dtype(np.uint64)
393395
_dtype_validation_metadata = (is_unsigned_integer_dtype, "unsigned integer")
394396

397+
@property
398+
def _engine_type(self) -> type[libindex.UInt64Engine]:
399+
return libindex.UInt64Engine
400+
395401

396402
class Float64Index(NumericIndex):
397403
_index_descr_args = {

0 commit comments

Comments
 (0)