Skip to content

Commit f7df8bf

Browse files
authored
CLN: assorted (#51775)
* CLN: assorted * more specific * more accurate
1 parent 4d10233 commit f7df8bf

File tree

32 files changed

+111
-99
lines changed

32 files changed

+111
-99
lines changed

doc/source/whatsnew/v2.0.0.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,6 @@ Other API changes
790790
Deprecations
791791
~~~~~~~~~~~~
792792
- Deprecated parsing datetime strings with system-local timezone to ``tzlocal``, pass a ``tz`` keyword or explicitly call ``tz_localize`` instead (:issue:`50791`)
793-
- Deprecated silently dropping unrecognized timezones when parsing strings to datetimes (:issue:`18702`)
794793
- Deprecated argument ``infer_datetime_format`` in :func:`to_datetime` and :func:`read_csv`, as a strict version of it is now the default (:issue:`48621`)
795794
- Deprecated behavior of :func:`to_datetime` with ``unit`` when parsing strings, in a future version these will be parsed as datetimes (matching unit-less behavior) instead of cast to floats. To retain the old behavior, cast strings to numeric types before calling :func:`to_datetime` (:issue:`50735`)
796795
- Deprecated :func:`pandas.io.sql.execute` (:issue:`50185`)

doc/source/whatsnew/v2.1.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Other API changes
9292

9393
Deprecations
9494
~~~~~~~~~~~~
95+
- Deprecated silently dropping unrecognized timezones when parsing strings to datetimes (:issue:`18702`)
9596
- Deprecating pinning ``group.name`` to each group in :meth:`SeriesGroupBy.aggregate` aggregations; if your operation requires utilizing the groupby keys, iterate over the groupby object instead (:issue:`41090`)
9697
- Deprecated ``axis=1`` in :meth:`DataFrame.groupby` and in :class:`Grouper` constructor, do ``frame.T.groupby(...)`` instead (:issue:`51203`)
9798
- Deprecated passing a :class:`DataFrame` to :meth:`DataFrame.from_records`, use :meth:`DataFrame.set_index` or :meth:`DataFrame.drop` instead (:issue:`51353`)

pandas/_libs/arrays.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,12 @@ cdef class NDArrayBacked:
126126

127127
@property
128128
def size(self) -> int:
129-
return self._ndarray.size
129+
# TODO(cython3): use self._ndarray.size
130+
return cnp.PyArray_SIZE(self._ndarray)
130131

131132
@property
132133
def nbytes(self) -> int:
133-
return self._ndarray.nbytes
134+
return cnp.PyArray_NBYTES(self._ndarray)
134135

135136
def copy(self, order="C"):
136137
cdef:

pandas/_libs/parsers.pyi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,10 @@ class TextReader:
6767
def close(self) -> None: ...
6868
def read(self, rows: int | None = ...) -> dict[int, ArrayLike]: ...
6969
def read_low_memory(self, rows: int | None) -> list[dict[int, ArrayLike]]: ...
70+
71+
# _maybe_upcast, na_values are only exposed for testing
72+
na_values: dict
73+
74+
def _maybe_upcast(
75+
arr, use_nullable_dtypes: bool = ..., dtype_backend: str = ...
76+
) -> np.ndarray: ...

pandas/_libs/tslib.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ def array_to_datetime_with_tz(ndarray values, tzinfo tz):
695695
if ts is NaT:
696696
ival = NPY_NAT
697697
else:
698-
if ts.tz is not None:
698+
if ts.tzinfo is not None:
699699
ts = ts.tz_convert(tz)
700700
else:
701701
# datetime64, tznaive pydatetime, int, float

pandas/_libs/tslibs/conversion.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ cpdef inline (int64_t, int) precision_from_unit(
176176
multiplier = periods_per_second(out_reso)
177177
m = multiplier * 2629746
178178
else:
179+
# Careful: if get_conversion_factor raises, the exception does
180+
# not propagate, instead we get a warning about an ignored exception.
181+
# https://github.com/pandas-dev/pandas/pull/51483#discussion_r1115198951
179182
m = get_conversion_factor(reso, out_reso)
180183

181184
p = <int>log10(m) # number of digits in 'm' minus 1

pandas/_libs/tslibs/offsets.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4096,7 +4096,7 @@ cpdef to_offset(freq):
40964096
40974097
Returns
40984098
-------
4099-
DateOffset or None
4099+
BaseOffset subclass or None
41004100
41014101
Raises
41024102
------

pandas/_libs/tslibs/src/datetime/np_datetime.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -224,29 +224,6 @@ static npy_int64 days_to_yearsdays(npy_int64 *days_) {
224224
return year + 2000;
225225
}
226226

227-
/*
228-
* Adjusts a datetimestruct based on a seconds offset. Assumes
229-
* the current values are valid.
230-
*/
231-
NPY_NO_EXPORT void add_seconds_to_datetimestruct(npy_datetimestruct *dts,
232-
int seconds) {
233-
int minutes;
234-
235-
dts->sec += seconds;
236-
if (dts->sec < 0) {
237-
minutes = dts->sec / 60;
238-
dts->sec = dts->sec % 60;
239-
if (dts->sec < 0) {
240-
--minutes;
241-
dts->sec += 60;
242-
}
243-
add_minutes_to_datetimestruct(dts, minutes);
244-
} else if (dts->sec >= 60) {
245-
minutes = dts->sec / 60;
246-
dts->sec = dts->sec % 60;
247-
add_minutes_to_datetimestruct(dts, minutes);
248-
}
249-
}
250227

251228
/*
252229
* Fills in the year, month, day in 'dts' based on the days

pandas/_libs/tslibs/tzconversion.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ cdef int64_t tz_localize_to_utc_single(
153153
return val
154154

155155
elif is_utc(tz) or tz is None:
156-
# TODO: test with non-nano
157156
return val
158157

159158
elif is_tzlocal(tz):

pandas/_testing/asserters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,8 +1179,8 @@ def assert_frame_equal(
11791179

11801180
# compare by blocks
11811181
if by_blocks:
1182-
rblocks = right._to_dict_of_blocks()
1183-
lblocks = left._to_dict_of_blocks()
1182+
rblocks = right._to_dict_of_blocks(copy=False)
1183+
lblocks = left._to_dict_of_blocks(copy=False)
11841184
for dtype in list(set(list(lblocks.keys()) + list(rblocks.keys()))):
11851185
assert dtype in lblocks
11861186
assert dtype in rblocks

0 commit comments

Comments
 (0)