Skip to content

Commit 822ce17

Browse files
author
MarcoGorelli
committed
Merge remote-tracking branch 'upstream/main' into implementation-pdep-4
2 parents 6c4e42d + cdb905a commit 822ce17

19 files changed

+454
-436
lines changed

.github/workflows/python-dev.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
os: [ubuntu-latest, macOS-latest, windows-latest]
5555

5656
name: actions-311-dev
57-
timeout-minutes: 80
57+
timeout-minutes: 120
5858

5959
concurrency:
6060
#https://github.community/t/concurrecy-not-work-for-push/183068/7
@@ -75,7 +75,7 @@ jobs:
7575
run: |
7676
python --version
7777
python -m pip install --upgrade pip setuptools wheel
78-
python -m pip install git+https://github.com/numpy/numpy.git
78+
python -m pip install -i https://pypi.anaconda.org/scipy-wheels-nightly/simple numpy
7979
python -m pip install git+https://github.com/nedbat/coveragepy.git
8080
python -m pip install python-dateutil pytz cython hypothesis==6.52.1 pytest>=6.2.5 pytest-xdist pytest-cov pytest-asyncio>=0.17
8181
python -m pip list
@@ -84,7 +84,7 @@ jobs:
8484
- name: Build Pandas
8585
run: |
8686
python setup.py build_ext -q -j1
87-
python -m pip install -e . --no-build-isolation --no-use-pep517
87+
python -m pip install -e . --no-build-isolation --no-use-pep517 --no-index
8888
8989
- name: Build Version
9090
run: |

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ or for installing in [development mode](https://pip.pypa.io/en/latest/cli/pip_in
128128
python -m pip install -e . --no-build-isolation --no-use-pep517
129129
```
130130

131-
If you have `make`, you can also use `make develop` to run the same command.
132-
133131
or alternatively
134132

135133
```sh

pandas/core/arrays/datetimelike.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,8 @@ def _add_timedeltalike_scalar(self, other):
12751275

12761276
# PeriodArray overrides, so we only get here with DTA/TDA
12771277
self = cast("DatetimeArray | TimedeltaArray", self)
1278-
other = Timedelta(other)._as_unit(self._unit)
1278+
other = Timedelta(other)
1279+
self, other = self._ensure_matching_resos(other)
12791280
return self._add_timedeltalike(other)
12801281

12811282
def _add_timedelta_arraylike(self, other: TimedeltaArray):

pandas/core/construction.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
maybe_convert_platform,
4646
maybe_infer_to_datetimelike,
4747
maybe_upcast,
48-
sanitize_to_nanoseconds,
4948
)
5049
from pandas.core.dtypes.common import (
5150
is_datetime64_ns_dtype,
@@ -782,7 +781,9 @@ def _try_cast(
782781
if is_ndarray:
783782
arr = cast(np.ndarray, arr)
784783
if arr.dtype != object:
785-
return sanitize_to_nanoseconds(arr, copy=copy)
784+
if copy:
785+
return arr.copy()
786+
return arr
786787

787788
out = maybe_infer_to_datetimelike(arr)
788789
if out is arr and copy:

pandas/core/dtypes/cast.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1423,12 +1423,7 @@ def maybe_cast_to_datetime(
14231423
return astype_nansafe(value, dtype) # type: ignore[arg-type]
14241424

14251425
elif isinstance(value, np.ndarray):
1426-
if value.dtype.kind in ["M", "m"]:
1427-
# catch a datetime/timedelta that is not of ns variety
1428-
# and no coercion specified
1429-
value = sanitize_to_nanoseconds(value)
1430-
1431-
elif value.dtype == _dtype_obj:
1426+
if value.dtype == _dtype_obj:
14321427
value = maybe_infer_to_datetimelike(value)
14331428

14341429
elif isinstance(value, list):

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5878,7 +5878,7 @@ def pipe(
58785878
58795879
If you have a function that takes the data as (say) the second
58805880
argument, pass a tuple indicating which keyword expects the
5881-
data. For example, suppose ``f`` takes its data as ``arg2``:
5881+
data. For example, suppose ``func`` takes its data as ``arg2``:
58825882
58835883
>>> (df.pipe(h)
58845884
... .pipe(g, arg1=a)

pandas/core/groupby/grouper.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
from pandas.util._decorators import cache_readonly
2727
from pandas.util._exceptions import find_stack_level
2828

29-
from pandas.core.dtypes.cast import sanitize_to_nanoseconds
3029
from pandas.core.dtypes.common import (
3130
is_categorical_dtype,
3231
is_list_like,
@@ -558,9 +557,12 @@ def __init__(
558557
raise AssertionError(errmsg)
559558

560559
if isinstance(self.grouping_vector, np.ndarray):
561-
# if we have a date/time-like grouper, make sure that we have
562-
# Timestamps like
563-
self.grouping_vector = sanitize_to_nanoseconds(self.grouping_vector)
560+
if self.grouping_vector.dtype.kind in ["m", "M"]:
561+
# if we have a date/time-like grouper, make sure that we have
562+
# Timestamps like
563+
# TODO 2022-10-08 we only have one test that gets here and
564+
# values are already in nanoseconds in that case.
565+
self.grouping_vector = Series(self.grouping_vector).to_numpy()
564566

565567
def __repr__(self) -> str:
566568
return f"Grouping({self.name})"

pandas/core/internals/blocks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1983,7 +1983,7 @@ def _catch_deprecated_value_error(err: Exception) -> None:
19831983
# IntervalDtype mismatched 'closed'
19841984
pass
19851985
elif "Timezones don't match" not in str(err):
1986-
raise
1986+
raise err
19871987

19881988

19891989
class DatetimeLikeBlock(NDArrayBackedExtensionBlock):

pandas/tests/frame/test_query_eval.py

+23-20
Original file line numberDiff line numberDiff line change
@@ -36,45 +36,48 @@ def skip_if_no_pandas_parser(parser):
3636

3737

3838
class TestCompat:
39-
def setup_method(self):
40-
self.df = DataFrame({"A": [1, 2, 3]})
41-
self.expected1 = self.df[self.df.A > 0]
42-
self.expected2 = self.df.A + 1
39+
@pytest.fixture
40+
def df(self):
41+
return DataFrame({"A": [1, 2, 3]})
42+
43+
@pytest.fixture
44+
def expected1(self, df):
45+
return df[df.A > 0]
46+
47+
@pytest.fixture
48+
def expected2(self, df):
49+
return df.A + 1
4350

44-
def test_query_default(self):
51+
def test_query_default(self, df, expected1, expected2):
4552

4653
# GH 12749
4754
# this should always work, whether NUMEXPR_INSTALLED or not
48-
df = self.df
4955
result = df.query("A>0")
50-
tm.assert_frame_equal(result, self.expected1)
56+
tm.assert_frame_equal(result, expected1)
5157
result = df.eval("A+1")
52-
tm.assert_series_equal(result, self.expected2, check_names=False)
58+
tm.assert_series_equal(result, expected2, check_names=False)
5359

54-
def test_query_None(self):
60+
def test_query_None(self, df, expected1, expected2):
5561

56-
df = self.df
5762
result = df.query("A>0", engine=None)
58-
tm.assert_frame_equal(result, self.expected1)
63+
tm.assert_frame_equal(result, expected1)
5964
result = df.eval("A+1", engine=None)
60-
tm.assert_series_equal(result, self.expected2, check_names=False)
65+
tm.assert_series_equal(result, expected2, check_names=False)
6166

62-
def test_query_python(self):
67+
def test_query_python(self, df, expected1, expected2):
6368

64-
df = self.df
6569
result = df.query("A>0", engine="python")
66-
tm.assert_frame_equal(result, self.expected1)
70+
tm.assert_frame_equal(result, expected1)
6771
result = df.eval("A+1", engine="python")
68-
tm.assert_series_equal(result, self.expected2, check_names=False)
72+
tm.assert_series_equal(result, expected2, check_names=False)
6973

70-
def test_query_numexpr(self):
74+
def test_query_numexpr(self, df, expected1, expected2):
7175

72-
df = self.df
7376
if NUMEXPR_INSTALLED:
7477
result = df.query("A>0", engine="numexpr")
75-
tm.assert_frame_equal(result, self.expected1)
78+
tm.assert_frame_equal(result, expected1)
7679
result = df.eval("A+1", engine="numexpr")
77-
tm.assert_series_equal(result, self.expected2, check_names=False)
80+
tm.assert_series_equal(result, expected2, check_names=False)
7881
else:
7982
msg = (
8083
r"'numexpr' is not installed or an unsupported version. "

pandas/tests/io/json/test_json_table_schema_ext_dtype.py

+33-20
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,36 @@ def test_as_json_table_type_ext_integer_dtype(self):
111111

112112

113113
class TestTableOrient:
114-
def setup_method(self):
115-
self.da = DateArray([dt.date(2021, 10, 10)])
116-
self.dc = DecimalArray([decimal.Decimal(10)])
117-
self.sa = array(["pandas"], dtype="string")
118-
self.ia = array([10], dtype="Int64")
119-
self.df = DataFrame(
114+
@pytest.fixture
115+
def da(self):
116+
return DateArray([dt.date(2021, 10, 10)])
117+
118+
@pytest.fixture
119+
def dc(self):
120+
return DecimalArray([decimal.Decimal(10)])
121+
122+
@pytest.fixture
123+
def sa(self):
124+
return array(["pandas"], dtype="string")
125+
126+
@pytest.fixture
127+
def ia(self):
128+
return array([10], dtype="Int64")
129+
130+
@pytest.fixture
131+
def df(self, da, dc, sa, ia):
132+
return DataFrame(
120133
{
121-
"A": self.da,
122-
"B": self.dc,
123-
"C": self.sa,
124-
"D": self.ia,
134+
"A": da,
135+
"B": dc,
136+
"C": sa,
137+
"D": ia,
125138
}
126139
)
127140

128-
def test_build_date_series(self):
141+
def test_build_date_series(self, da):
129142

130-
s = Series(self.da, name="a")
143+
s = Series(da, name="a")
131144
s.index.name = "id"
132145
result = s.to_json(orient="table", date_format="iso")
133146
result = json.loads(result, object_pairs_hook=OrderedDict)
@@ -151,9 +164,9 @@ def test_build_date_series(self):
151164

152165
assert result == expected
153166

154-
def test_build_decimal_series(self):
167+
def test_build_decimal_series(self, dc):
155168

156-
s = Series(self.dc, name="a")
169+
s = Series(dc, name="a")
157170
s.index.name = "id"
158171
result = s.to_json(orient="table", date_format="iso")
159172
result = json.loads(result, object_pairs_hook=OrderedDict)
@@ -177,8 +190,8 @@ def test_build_decimal_series(self):
177190

178191
assert result == expected
179192

180-
def test_build_string_series(self):
181-
s = Series(self.sa, name="a")
193+
def test_build_string_series(self, sa):
194+
s = Series(sa, name="a")
182195
s.index.name = "id"
183196
result = s.to_json(orient="table", date_format="iso")
184197
result = json.loads(result, object_pairs_hook=OrderedDict)
@@ -202,8 +215,8 @@ def test_build_string_series(self):
202215

203216
assert result == expected
204217

205-
def test_build_int64_series(self):
206-
s = Series(self.ia, name="a")
218+
def test_build_int64_series(self, ia):
219+
s = Series(ia, name="a")
207220
s.index.name = "id"
208221
result = s.to_json(orient="table", date_format="iso")
209222
result = json.loads(result, object_pairs_hook=OrderedDict)
@@ -227,9 +240,9 @@ def test_build_int64_series(self):
227240

228241
assert result == expected
229242

230-
def test_to_json(self):
243+
def test_to_json(self, df):
231244

232-
df = self.df.copy()
245+
df = df.copy()
233246
df.index.name = "idx"
234247
result = df.to_json(orient="table", date_format="iso")
235248
result = json.loads(result, object_pairs_hook=OrderedDict)

pandas/tests/plotting/test_converter.py

+27-23
Original file line numberDiff line numberDiff line change
@@ -287,66 +287,70 @@ def test_convert_nested(self, dtc):
287287

288288

289289
class TestPeriodConverter:
290-
def setup_method(self):
291-
self.pc = converter.PeriodConverter()
290+
@pytest.fixture
291+
def pc(self):
292+
return converter.PeriodConverter()
292293

294+
@pytest.fixture
295+
def axis(self):
293296
class Axis:
294297
pass
295298

296-
self.axis = Axis()
297-
self.axis.freq = "D"
299+
axis = Axis()
300+
axis.freq = "D"
301+
return axis
298302

299-
def test_convert_accepts_unicode(self):
300-
r1 = self.pc.convert("2012-1-1", None, self.axis)
301-
r2 = self.pc.convert("2012-1-1", None, self.axis)
303+
def test_convert_accepts_unicode(self, pc, axis):
304+
r1 = pc.convert("2012-1-1", None, axis)
305+
r2 = pc.convert("2012-1-1", None, axis)
302306
assert r1 == r2
303307

304-
def test_conversion(self):
305-
rs = self.pc.convert(["2012-1-1"], None, self.axis)[0]
308+
def test_conversion(self, pc, axis):
309+
rs = pc.convert(["2012-1-1"], None, axis)[0]
306310
xp = Period("2012-1-1").ordinal
307311
assert rs == xp
308312

309-
rs = self.pc.convert("2012-1-1", None, self.axis)
313+
rs = pc.convert("2012-1-1", None, axis)
310314
assert rs == xp
311315

312-
rs = self.pc.convert([date(2012, 1, 1)], None, self.axis)[0]
316+
rs = pc.convert([date(2012, 1, 1)], None, axis)[0]
313317
assert rs == xp
314318

315-
rs = self.pc.convert(date(2012, 1, 1), None, self.axis)
319+
rs = pc.convert(date(2012, 1, 1), None, axis)
316320
assert rs == xp
317321

318-
rs = self.pc.convert([Timestamp("2012-1-1")], None, self.axis)[0]
322+
rs = pc.convert([Timestamp("2012-1-1")], None, axis)[0]
319323
assert rs == xp
320324

321-
rs = self.pc.convert(Timestamp("2012-1-1"), None, self.axis)
325+
rs = pc.convert(Timestamp("2012-1-1"), None, axis)
322326
assert rs == xp
323327

324-
rs = self.pc.convert("2012-01-01", None, self.axis)
328+
rs = pc.convert("2012-01-01", None, axis)
325329
assert rs == xp
326330

327-
rs = self.pc.convert("2012-01-01 00:00:00+0000", None, self.axis)
331+
rs = pc.convert("2012-01-01 00:00:00+0000", None, axis)
328332
assert rs == xp
329333

330-
rs = self.pc.convert(
334+
rs = pc.convert(
331335
np.array(
332336
["2012-01-01 00:00:00", "2012-01-02 00:00:00"],
333337
dtype="datetime64[ns]",
334338
),
335339
None,
336-
self.axis,
340+
axis,
337341
)
338342
assert rs[0] == xp
339343

340-
def test_integer_passthrough(self):
344+
def test_integer_passthrough(self, pc, axis):
341345
# GH9012
342-
rs = self.pc.convert([0, 1], None, self.axis)
346+
rs = pc.convert([0, 1], None, axis)
343347
xp = [0, 1]
344348
assert rs == xp
345349

346-
def test_convert_nested(self):
350+
def test_convert_nested(self, pc, axis):
347351
data = ["2012-1-1", "2012-1-2"]
348-
r1 = self.pc.convert([data, data], None, self.axis)
349-
r2 = [self.pc.convert(data, None, self.axis) for _ in range(2)]
352+
r1 = pc.convert([data, data], None, axis)
353+
r2 = [pc.convert(data, None, axis) for _ in range(2)]
350354
assert r1 == r2
351355

352356

0 commit comments

Comments
 (0)