Skip to content

Commit e88a9cb

Browse files
authored
Merge branch 'main' into bugfix/57539-fix-to-sql
2 parents 25bd776 + 192db0d commit e88a9cb

File tree

22 files changed

+55
-94
lines changed

22 files changed

+55
-94
lines changed

doc/source/whatsnew/v2.2.2.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ Fixed regressions
1515
~~~~~~~~~~~~~~~~~
1616
- :meth:`DataFrame.__dataframe__` was producing incorrect data buffers when the a column's type was a pandas nullable on with missing values (:issue:`56702`)
1717
- :meth:`DataFrame.__dataframe__` was producing incorrect data buffers when the a column's type was a pyarrow nullable on with missing values (:issue:`57664`)
18-
-
18+
- Fixed regression in precision of :func:`to_datetime` with string and ``unit`` input (:issue:`57051`)
1919

2020
.. ---------------------------------------------------------------------------
2121
.. _whatsnew_222.bug_fixes:
2222

2323
Bug fixes
2424
~~~~~~~~~
25+
- :meth:`DataFrame.__dataframe__` was producing incorrect data buffers when the column's type was nullable boolean (:issue:`55332`)
2526
- :meth:`DataFrame.__dataframe__` was showing bytemask instead of bitmask for ``'string[pyarrow]'`` validity buffer (:issue:`57762`)
2627
- :meth:`DataFrame.__dataframe__` was showing non-null validity buffer (instead of ``None``) ``'string[pyarrow]'`` without missing values (:issue:`57761`)
2728
- :meth:`DataFrame.to_sql` was failing to find the right table when using the schema argument (:issue:`57539`)

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ Removal of prior version deprecations/changes
206206
- :meth:`SeriesGroupBy.agg` no longer pins the name of the group to the input passed to the provided ``func`` (:issue:`51703`)
207207
- All arguments except ``name`` in :meth:`Index.rename` are now keyword only (:issue:`56493`)
208208
- All arguments except the first ``path``-like argument in IO writers are now keyword only (:issue:`54229`)
209+
- Removed "freq" keyword from :class:`PeriodArray` constructor, use "dtype" instead (:issue:`52462`)
209210
- Removed the "closed" and "normalize" keywords in :meth:`DatetimeIndex.__new__` (:issue:`52628`)
210211
- Removed the "closed" and "unit" keywords in :meth:`TimedeltaIndex.__new__` (:issue:`52628`, :issue:`55499`)
211212
- All arguments in :meth:`Index.sort_values` are now keyword only (:issue:`56493`)

pandas/_libs/tslib.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def array_with_unit_to_datetime(
275275
bint is_raise = errors == "raise"
276276
ndarray[int64_t] iresult
277277
tzinfo tz = None
278-
float fval
278+
double fval
279279

280280
assert is_coerce or is_raise
281281

pandas/core/arrays/period.py

+1-20
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
cache_readonly,
5555
doc,
5656
)
57-
from pandas.util._exceptions import find_stack_level
5857

5958
from pandas.core.dtypes.common import (
6059
ensure_object,
@@ -135,11 +134,6 @@ class PeriodArray(dtl.DatelikeOps, libperiod.PeriodMixin): # type: ignore[misc]
135134
dtype : PeriodDtype, optional
136135
A PeriodDtype instance from which to extract a `freq`. If both
137136
`freq` and `dtype` are specified, then the frequencies must match.
138-
freq : str or DateOffset
139-
The `freq` to use for the array. Mostly applicable when `values`
140-
is an ndarray of integers, when `freq` is required. When `values`
141-
is a PeriodArray (or box around), it's checked that ``values.freq``
142-
matches `freq`.
143137
copy : bool, default False
144138
Whether to copy the ordinals before storing.
145139
@@ -224,20 +218,7 @@ def _scalar_type(self) -> type[Period]:
224218
# --------------------------------------------------------------------
225219
# Constructors
226220

227-
def __init__(
228-
self, values, dtype: Dtype | None = None, freq=None, copy: bool = False
229-
) -> None:
230-
if freq is not None:
231-
# GH#52462
232-
warnings.warn(
233-
"The 'freq' keyword in the PeriodArray constructor is deprecated "
234-
"and will be removed in a future version. Pass 'dtype' instead",
235-
FutureWarning,
236-
stacklevel=find_stack_level(),
237-
)
238-
freq = validate_dtype_freq(dtype, freq)
239-
dtype = PeriodDtype(freq)
240-
221+
def __init__(self, values, dtype: Dtype | None = None, copy: bool = False) -> None:
241222
if dtype is not None:
242223
dtype = pandas_dtype(dtype)
243224
if not isinstance(dtype, PeriodDtype):

pandas/core/generic.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -9660,13 +9660,7 @@ def _where(
96609660

96619661
# make sure we are boolean
96629662
fill_value = bool(inplace)
9663-
with warnings.catch_warnings():
9664-
warnings.filterwarnings(
9665-
"ignore",
9666-
"Downcasting object dtype arrays",
9667-
category=FutureWarning,
9668-
)
9669-
cond = cond.fillna(fill_value)
9663+
cond = cond.fillna(fill_value)
96709664
cond = cond.infer_objects()
96719665

96729666
msg = "Boolean array expected for the condition, not {dtype}"

pandas/core/interchange/utils.py

+3
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ def dtype_to_arrow_c_fmt(dtype: DtypeObj) -> str:
144144
elif isinstance(dtype, DatetimeTZDtype):
145145
return ArrowCTypes.TIMESTAMP.format(resolution=dtype.unit[0], tz=dtype.tz)
146146

147+
elif isinstance(dtype, pd.BooleanDtype):
148+
return ArrowCTypes.BOOL
149+
147150
raise NotImplementedError(
148151
f"Conversion of {dtype} to Arrow C format string is not implemented."
149152
)

pandas/core/reshape/reshape.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -932,14 +932,18 @@ def stack_v3(frame: DataFrame, level: list[int]) -> Series | DataFrame:
932932
if len(frame.columns) == 1:
933933
data = frame.copy()
934934
else:
935-
# Take the data from frame corresponding to this idx value
936-
if len(level) == 1:
937-
idx = (idx,)
938-
gen = iter(idx)
939-
column_indexer = tuple(
940-
next(gen) if k in set_levels else slice(None)
941-
for k in range(frame.columns.nlevels)
942-
)
935+
if not isinstance(frame.columns, MultiIndex) and not isinstance(idx, tuple):
936+
# GH#57750 - if the frame is an Index with tuples, .loc below will fail
937+
column_indexer = idx
938+
else:
939+
# Take the data from frame corresponding to this idx value
940+
if len(level) == 1:
941+
idx = (idx,)
942+
gen = iter(idx)
943+
column_indexer = tuple(
944+
next(gen) if k in set_levels else slice(None)
945+
for k in range(frame.columns.nlevels)
946+
)
943947
data = frame.loc[:, column_indexer]
944948

945949
if len(level) < frame.columns.nlevels:

pandas/io/formats/xml.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
Any,
1212
final,
1313
)
14-
import warnings
1514

1615
from pandas.errors import AbstractMethodError
1716
from pandas.util._decorators import (
@@ -208,13 +207,7 @@ def _process_dataframe(self) -> dict[int | str, dict[str, Any]]:
208207
df = df.reset_index()
209208

210209
if self.na_rep is not None:
211-
with warnings.catch_warnings():
212-
warnings.filterwarnings(
213-
"ignore",
214-
"Downcasting object dtype arrays",
215-
category=FutureWarning,
216-
)
217-
df = df.fillna(self.na_rep)
210+
df = df.fillna(self.na_rep)
218211

219212
return df.to_dict(orient="index")
220213

pandas/io/json/_json.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
final,
1717
overload,
1818
)
19-
import warnings
2019

2120
import numpy as np
2221

@@ -1173,13 +1172,7 @@ def _try_convert_data(
11731172
if all(notna(data)):
11741173
return data, False
11751174

1176-
with warnings.catch_warnings():
1177-
warnings.filterwarnings(
1178-
"ignore",
1179-
"Downcasting object dtype arrays",
1180-
category=FutureWarning,
1181-
)
1182-
filled = data.fillna(np.nan)
1175+
filled = data.fillna(np.nan)
11831176

11841177
return filled, True
11851178

pandas/io/stata.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -2887,13 +2887,7 @@ def _prepare_data(self) -> np.rec.recarray:
28872887
for i, col in enumerate(data):
28882888
typ = typlist[i]
28892889
if typ <= self._max_string_length:
2890-
with warnings.catch_warnings():
2891-
warnings.filterwarnings(
2892-
"ignore",
2893-
"Downcasting object dtype arrays",
2894-
category=FutureWarning,
2895-
)
2896-
dc = data[col].fillna("")
2890+
dc = data[col].fillna("")
28972891
data[col] = dc.apply(_pad_bytes, args=(typ,))
28982892
stype = f"S{typ}"
28992893
dtypes[col] = stype

pandas/plotting/_matplotlib/core.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -1725,13 +1725,7 @@ def _kind(self) -> Literal["area"]:
17251725

17261726
def __init__(self, data, **kwargs) -> None:
17271727
kwargs.setdefault("stacked", True)
1728-
with warnings.catch_warnings():
1729-
warnings.filterwarnings(
1730-
"ignore",
1731-
"Downcasting object dtype arrays",
1732-
category=FutureWarning,
1733-
)
1734-
data = data.fillna(value=0)
1728+
data = data.fillna(value=0)
17351729
LinePlot.__init__(self, data, **kwargs)
17361730

17371731
if not self.stacked:

pandas/tests/arrays/period/test_constructors.py

-11
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,6 @@ def test_from_td64nat_sequence_raises():
135135
pd.DataFrame(arr, dtype=dtype)
136136

137137

138-
def test_freq_deprecated():
139-
# GH#52462
140-
data = np.arange(5).astype(np.int64)
141-
msg = "The 'freq' keyword in the PeriodArray constructor is deprecated"
142-
with tm.assert_produces_warning(FutureWarning, match=msg):
143-
res = PeriodArray(data, freq="M")
144-
145-
expected = PeriodArray(data, dtype="period[M]")
146-
tm.assert_equal(res, expected)
147-
148-
149138
def test_period_array_from_datetime64():
150139
arr = np.array(
151140
["2020-01-01T00:00:00", "2020-02-02T00:00:00"], dtype="datetime64[ns]"

pandas/tests/extension/test_masked.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
1515
"""
1616

17-
import warnings
18-
1917
import numpy as np
2018
import pytest
2119

@@ -215,13 +213,7 @@ def _cast_pointwise_result(self, op_name: str, obj, other, pointwise_result):
215213

216214
if sdtype.kind in "iu":
217215
if op_name in ("__rtruediv__", "__truediv__", "__div__"):
218-
with warnings.catch_warnings():
219-
warnings.filterwarnings(
220-
"ignore",
221-
"Downcasting object dtype arrays",
222-
category=FutureWarning,
223-
)
224-
filled = expected.fillna(np.nan)
216+
filled = expected.fillna(np.nan)
225217
expected = filled.astype("Float64")
226218
else:
227219
# combine method result in 'biggest' (int64) dtype

pandas/tests/frame/indexing/test_where.py

-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ def test_where_upcasting(self):
9696

9797
tm.assert_series_equal(result, expected)
9898

99-
@pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning")
10099
def test_where_alignment(self, where_frame, float_string_frame):
101100
# aligning
102101
def _check_align(df, cond, other, check_dtypes=True):
@@ -171,7 +170,6 @@ def test_where_invalid(self):
171170
with pytest.raises(ValueError, match=msg):
172171
df.mask(0)
173172

174-
@pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning")
175173
def test_where_set(self, where_frame, float_string_frame, mixed_int_frame):
176174
# where inplace
177175

pandas/tests/frame/test_reductions.py

-1
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,6 @@ def test_any_all_bool_with_na(
12721272
):
12731273
getattr(bool_frame_with_na, all_boolean_reductions)(axis=axis, bool_only=False)
12741274

1275-
@pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning")
12761275
def test_any_all_bool_frame(self, all_boolean_reductions, bool_frame_with_na):
12771276
# GH#12863: numpy gives back non-boolean data for object type
12781277
# so fill NaNs to compare with pandas behavior

pandas/tests/frame/test_stack_unstack.py

-1
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,6 @@ def test_stack_preserve_categorical_dtype_values(self, future_stack):
12231223
@pytest.mark.filterwarnings(
12241224
"ignore:The previous implementation of stack is deprecated"
12251225
)
1226-
@pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning")
12271226
@pytest.mark.parametrize(
12281227
"index",
12291228
[

pandas/tests/groupby/test_numeric_only.py

-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ def test_numeric_only(kernel, has_arg, numeric_only, keys):
310310
method(*args, **kwargs)
311311

312312

313-
@pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning")
314313
@pytest.mark.parametrize("dtype", [bool, int, float, object])
315314
def test_deprecate_numeric_only_series(dtype, groupby_func, request):
316315
# GH#46560

pandas/tests/interchange/test_impl.py

+2
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ def test_non_str_names_w_duplicates():
459459
),
460460
([1.0, 2.25, None], "Float32", "float32"),
461461
([1.0, 2.25, None], "Float32[pyarrow]", "float32"),
462+
([True, False, None], "boolean", "bool"),
462463
([True, False, None], "boolean[pyarrow]", "bool"),
463464
(["much ado", "about", None], "string[pyarrow_numpy]", "large_string"),
464465
(["much ado", "about", None], "string[pyarrow]", "large_string"),
@@ -521,6 +522,7 @@ def test_pandas_nullable_with_missing_values(
521522
),
522523
([1.0, 2.25, 5.0], "Float32", "float32"),
523524
([1.0, 2.25, 5.0], "Float32[pyarrow]", "float32"),
525+
([True, False, False], "boolean", "bool"),
524526
([True, False, False], "boolean[pyarrow]", "bool"),
525527
(["much ado", "about", "nothing"], "string[pyarrow_numpy]", "large_string"),
526528
(["much ado", "about", "nothing"], "string[pyarrow]", "large_string"),

pandas/tests/series/test_api.py

-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ def test_series_datetimelike_attribute_access_invalid(self):
195195
with pytest.raises(AttributeError, match=msg):
196196
ser.weekday
197197

198-
@pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning")
199198
@pytest.mark.parametrize(
200199
"kernel, has_numeric_only",
201200
[

pandas/tests/series/test_logical_ops.py

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616

1717
class TestSeriesLogicalOps:
18-
@pytest.mark.filterwarnings("ignore:Downcasting object dtype arrays:FutureWarning")
1918
@pytest.mark.parametrize("bool_op", [operator.and_, operator.or_, operator.xor])
2019
def test_bool_operators_with_nas(self, bool_op):
2120
# boolean &, |, ^ should work with object arrays and propagate NAs

pandas/tests/tools/test_to_datetime.py

+8
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,14 @@ def test_unit(self, cache):
17351735
with pytest.raises(ValueError, match=msg):
17361736
to_datetime([1], unit="D", format="%Y%m%d", cache=cache)
17371737

1738+
def test_unit_str(self, cache):
1739+
# GH 57051
1740+
# Test that strs aren't dropping precision to 32-bit accidentally.
1741+
with tm.assert_produces_warning(FutureWarning):
1742+
res = to_datetime(["1704660000"], unit="s", origin="unix")
1743+
expected = to_datetime([1704660000], unit="s", origin="unix")
1744+
tm.assert_index_equal(res, expected)
1745+
17381746
def test_unit_array_mixed_nans(self, cache):
17391747
values = [11111111111111111, 1, 1.0, iNaT, NaT, np.nan, "NaT", ""]
17401748

web/pandas/community/ecosystem.md

+19
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ pd.set_option("plotting.backend", "pandas_bokeh")
8282
It is very similar to the matplotlib plotting backend, but provides
8383
interactive web-based charts and maps.
8484

85+
### [pygwalker](https://github.com/Kanaries/pygwalker)
86+
87+
PyGWalker is an interactive data visualization and
88+
exploratory data analysis tool built upon Graphic Walker
89+
with support for visualization, cleaning, and annotation workflows.
90+
91+
pygwalker can save interactively created charts
92+
to Graphic-Walker and Vega-Lite JSON.
93+
94+
```
95+
import pygwalker as pyg
96+
pyg.walk(df)
97+
```
98+
8599
### [seaborn](https://seaborn.pydata.org)
86100

87101
Seaborn is a Python visualization library based on
@@ -94,6 +108,11 @@ pandas with the option to perform statistical estimation while plotting,
94108
aggregating across observations and visualizing the fit of statistical
95109
models to emphasize patterns in a dataset.
96110

111+
```
112+
import seaborn as sns
113+
sns.set_theme()
114+
```
115+
97116
### [plotnine](https://github.com/has2k1/plotnine/)
98117

99118
Hadley Wickham's [ggplot2](https://ggplot2.tidyverse.org/) is a

0 commit comments

Comments
 (0)