Skip to content

Commit 6375977

Browse files
committed
Merge remote-tracking branch 'upstream/master' into test_pytables_refactor
2 parents cfdd437 + 4e5c9d4 commit 6375977

File tree

11 files changed

+78
-87
lines changed

11 files changed

+78
-87
lines changed

pandas/core/dtypes/cast.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,21 @@ def maybe_promote(dtype, fill_value=np.nan):
350350

351351
# returns tuple of (dtype, fill_value)
352352
if issubclass(dtype.type, np.datetime64):
353-
fill_value = tslibs.Timestamp(fill_value).to_datetime64()
353+
try:
354+
fill_value = tslibs.Timestamp(fill_value).to_datetime64()
355+
except (TypeError, ValueError):
356+
dtype = np.dtype(np.object_)
354357
elif issubclass(dtype.type, np.timedelta64):
355-
fv = tslibs.Timedelta(fill_value)
356-
if fv is NaT:
357-
# NaT has no `to_timedelta6` method
358-
fill_value = np.timedelta64("NaT", "ns")
358+
try:
359+
fv = tslibs.Timedelta(fill_value)
360+
except ValueError:
361+
dtype = np.dtype(np.object_)
359362
else:
360-
fill_value = fv.to_timedelta64()
363+
if fv is NaT:
364+
# NaT has no `to_timedelta64` method
365+
fill_value = np.timedelta64("NaT", "ns")
366+
else:
367+
fill_value = fv.to_timedelta64()
361368
elif is_datetime64tz_dtype(dtype):
362369
if isna(fill_value):
363370
fill_value = NaT

pandas/core/frame.py

+6-13
Original file line numberDiff line numberDiff line change
@@ -5279,24 +5279,17 @@ def _arith_op(left, right):
52795279
new_data = dispatch_fill_zeros(func, this.values, other.values, res_values)
52805280
return this._construct_result(new_data)
52815281

5282-
def _combine_match_index(self, other, func, level=None):
5283-
left, right = self.align(other, join="outer", axis=0, level=level, copy=False)
5284-
# at this point we have `left.index.equals(right.index)`
5282+
def _combine_match_index(self, other, func):
5283+
# at this point we have `self.index.equals(other.index)`
52855284

5286-
if left._is_mixed_type or right._is_mixed_type:
5285+
if self._is_mixed_type or other._is_mixed_type:
52875286
# operate column-wise; avoid costly object-casting in `.values`
5288-
new_data = ops.dispatch_to_series(left, right, func)
5287+
new_data = ops.dispatch_to_series(self, other, func)
52895288
else:
52905289
# fastpath --> operate directly on values
52915290
with np.errstate(all="ignore"):
5292-
new_data = func(left.values.T, right.values).T
5293-
return left._construct_result(new_data)
5294-
5295-
def _combine_match_columns(self, other: Series, func, level=None):
5296-
left, right = self.align(other, join="outer", axis=1, level=level, copy=False)
5297-
# at this point we have `left.columns.equals(right.index)`
5298-
new_data = ops.dispatch_to_series(left, right, func, axis="columns")
5299-
return left._construct_result(new_data)
5291+
new_data = func(self.values.T, other.values).T
5292+
return new_data
53005293

53015294
def _construct_result(self, result) -> "DataFrame":
53025295
"""

pandas/core/indexes/timedeltas.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -717,17 +717,17 @@ def timedelta_range(
717717
718718
Parameters
719719
----------
720-
start : string or timedelta-like, default None
720+
start : str or timedelta-like, default None
721721
Left bound for generating timedeltas
722-
end : string or timedelta-like, default None
722+
end : str or timedelta-like, default None
723723
Right bound for generating timedeltas
724-
periods : integer, default None
724+
periods : int, default None
725725
Number of periods to generate
726-
freq : string or DateOffset, default 'D'
726+
freq : str or DateOffset, default 'D'
727727
Frequency strings can have multiples, e.g. '5H'
728-
name : string, default None
728+
name : str, default None
729729
Name of the resulting TimedeltaIndex
730-
closed : string, default None
730+
closed : str, default None
731731
Make the interval closed with respect to the given frequency to
732732
the 'left', 'right', or both sides (None)
733733

pandas/core/ops/__init__.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def column_op(a, b):
384384
return {i: func(a.iloc[:, i], b.iloc[:, i]) for i in range(len(a.columns))}
385385

386386
elif isinstance(right, ABCSeries) and axis == "columns":
387-
# We only get here if called via left._combine_match_columns,
387+
# We only get here if called via _combine_frame_series,
388388
# in which case we specifically want to operate row-by-row
389389
assert right.index.equals(left.columns)
390390

@@ -613,15 +613,18 @@ def _combine_series_frame(self, other, func, fill_value=None, axis=None, level=N
613613
"fill_value {fill} not supported.".format(fill=fill_value)
614614
)
615615

616-
if axis is not None:
617-
axis = self._get_axis_number(axis)
618-
if axis == 0:
619-
return self._combine_match_index(other, func, level=level)
620-
else:
621-
return self._combine_match_columns(other, func, level=level)
616+
if axis is None:
617+
# default axis is columns
618+
axis = 1
619+
620+
axis = self._get_axis_number(axis)
621+
left, right = self.align(other, join="outer", axis=axis, level=level, copy=False)
622+
if axis == 0:
623+
new_data = left._combine_match_index(right, func)
624+
else:
625+
new_data = dispatch_to_series(left, right, func, axis="columns")
622626

623-
# default axis is columns
624-
return self._combine_match_columns(other, func, level=level)
627+
return left._construct_result(new_data)
625628

626629

627630
def _align_method_FRAME(left, right, axis):

pandas/io/formats/style.py

+31-31
Original file line numberDiff line numberDiff line change
@@ -642,16 +642,16 @@ def apply(self, func, axis=0, subset=None, **kwargs):
642642
``func`` should take a Series or DataFrame (depending
643643
on ``axis``), and return an object with the same shape.
644644
Must return a DataFrame with identical index and
645-
column labels when ``axis=None``
645+
column labels when ``axis=None``.
646646
axis : {0 or 'index', 1 or 'columns', None}, default 0
647-
apply to each column (``axis=0`` or ``'index'``), to each row
647+
Apply to each column (``axis=0`` or ``'index'``), to each row
648648
(``axis=1`` or ``'columns'``), or to the entire DataFrame at once
649649
with ``axis=None``.
650650
subset : IndexSlice
651-
a valid indexer to limit ``data`` to *before* applying the
652-
function. Consider using a pandas.IndexSlice
651+
A valid indexer to limit ``data`` to *before* applying the
652+
function. Consider using a pandas.IndexSlice.
653653
**kwargs : dict
654-
pass along to ``func``
654+
Pass along to ``func``.
655655
656656
Returns
657657
-------
@@ -698,12 +698,12 @@ def applymap(self, func, subset=None, **kwargs):
698698
Parameters
699699
----------
700700
func : function
701-
``func`` should take a scalar and return a scalar
701+
``func`` should take a scalar and return a scalar.
702702
subset : IndexSlice
703-
a valid indexer to limit ``data`` to *before* applying the
704-
function. Consider using a pandas.IndexSlice
703+
A valid indexer to limit ``data`` to *before* applying the
704+
function. Consider using a pandas.IndexSlice.
705705
**kwargs : dict
706-
pass along to ``func``
706+
Pass along to ``func``.
707707
708708
Returns
709709
-------
@@ -729,16 +729,16 @@ def where(self, cond, value, other=None, subset=None, **kwargs):
729729
Parameters
730730
----------
731731
cond : callable
732-
``cond`` should take a scalar and return a boolean
732+
``cond`` should take a scalar and return a boolean.
733733
value : str
734-
applied when ``cond`` returns true
734+
Applied when ``cond`` returns true.
735735
other : str
736-
applied when ``cond`` returns false
736+
Applied when ``cond`` returns false.
737737
subset : IndexSlice
738-
a valid indexer to limit ``data`` to *before* applying the
739-
function. Consider using a pandas.IndexSlice
738+
A valid indexer to limit ``data`` to *before* applying the
739+
function. Consider using a pandas.IndexSlice.
740740
**kwargs : dict
741-
pass along to ``cond``
741+
Pass along to ``cond``.
742742
743743
Returns
744744
-------
@@ -819,7 +819,7 @@ def use(self, styles):
819819
Parameters
820820
----------
821821
styles : list
822-
list of style functions
822+
List of style functions.
823823
824824
Returns
825825
-------
@@ -969,19 +969,19 @@ def background_gradient(
969969
Parameters
970970
----------
971971
cmap : str or colormap
972-
matplotlib colormap
972+
Matplotlib colormap.
973973
low : float
974-
compress the range by the low.
974+
Compress the range by the low.
975975
high : float
976-
compress the range by the high.
976+
Compress the range by the high.
977977
axis : {0 or 'index', 1 or 'columns', None}, default 0
978-
apply to each column (``axis=0`` or ``'index'``), to each row
978+
Apply to each column (``axis=0`` or ``'index'``), to each row
979979
(``axis=1`` or ``'columns'``), or to the entire DataFrame at once
980980
with ``axis=None``.
981981
subset : IndexSlice
982-
a valid slice for ``data`` to limit the style application to.
982+
A valid slice for ``data`` to limit the style application to.
983983
text_color_threshold : float or int
984-
luminance threshold for determining text color. Facilitates text
984+
Luminance threshold for determining text color. Facilitates text
985985
visibility across varying background colors. From 0 to 1.
986986
0 = all text is dark colored, 1 = all text is light colored.
987987
@@ -1084,9 +1084,9 @@ def set_properties(self, subset=None, **kwargs):
10841084
Parameters
10851085
----------
10861086
subset : IndexSlice
1087-
a valid slice for ``data`` to limit the style application to
1087+
A valid slice for ``data`` to limit the style application to.
10881088
**kwargs : dict
1089-
property: value pairs to be set for each cell
1089+
A dictionary of property, value pairs to be set for each cell.
10901090
10911091
Returns
10921092
-------
@@ -1180,7 +1180,7 @@ def bar(
11801180
subset : IndexSlice, optional
11811181
A valid slice for `data` to limit the style application to.
11821182
axis : {0 or 'index', 1 or 'columns', None}, default 0
1183-
apply to each column (``axis=0`` or ``'index'``), to each row
1183+
Apply to each column (``axis=0`` or ``'index'``), to each row
11841184
(``axis=1`` or ``'columns'``), or to the entire DataFrame at once
11851185
with ``axis=None``.
11861186
color : str or 2-tuple/list
@@ -1256,10 +1256,10 @@ def highlight_max(self, subset=None, color="yellow", axis=0):
12561256
Parameters
12571257
----------
12581258
subset : IndexSlice, default None
1259-
a valid slice for ``data`` to limit the style application to.
1259+
A valid slice for ``data`` to limit the style application to.
12601260
color : str, default 'yellow'
12611261
axis : {0 or 'index', 1 or 'columns', None}, default 0
1262-
apply to each column (``axis=0`` or ``'index'``), to each row
1262+
Apply to each column (``axis=0`` or ``'index'``), to each row
12631263
(``axis=1`` or ``'columns'``), or to the entire DataFrame at once
12641264
with ``axis=None``.
12651265
@@ -1276,10 +1276,10 @@ def highlight_min(self, subset=None, color="yellow", axis=0):
12761276
Parameters
12771277
----------
12781278
subset : IndexSlice, default None
1279-
a valid slice for ``data`` to limit the style application to.
1279+
A valid slice for ``data`` to limit the style application to.
12801280
color : str, default 'yellow'
12811281
axis : {0 or 'index', 1 or 'columns', None}, default 0
1282-
apply to each column (``axis=0`` or ``'index'``), to each row
1282+
Apply to each column (``axis=0`` or ``'index'``), to each row
12831283
(``axis=1`` or ``'columns'``), or to the entire DataFrame at once
12841284
with ``axis=None``.
12851285
@@ -1328,9 +1328,9 @@ def from_custom_template(cls, searchpath, name):
13281328
Parameters
13291329
----------
13301330
searchpath : str or list
1331-
Path or paths of directories containing the templates
1331+
Path or paths of directories containing the templates.
13321332
name : str
1333-
Name of your custom template to use for rendering
1333+
Name of your custom template to use for rendering.
13341334
13351335
Returns
13361336
-------

pandas/io/json/_table_schema.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def build_table_schema(data, index=True, primary_key=None, version=True):
199199
index : bool, default True
200200
Whether to include ``data.index`` in the schema.
201201
primary_key : bool or None, default True
202-
column names to designate as the primary key.
202+
Column names to designate as the primary key.
203203
The default `None` will set `'primaryKey'` to the index
204204
level or levels if the index is unique.
205205
version : bool, default True

pandas/tests/dtypes/cast/test_promote.py

+1-17
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,6 @@ def test_maybe_promote_any_with_bool(any_numpy_dtype_reduced, box):
272272
pytest.xfail("falsely upcasts to object")
273273
if boxed and dtype not in (str, object) and box_dtype is None:
274274
pytest.xfail("falsely upcasts to object")
275-
if not boxed and dtype.kind == "M":
276-
pytest.xfail("raises error")
277-
if not boxed and dtype.kind == "m":
278-
pytest.xfail("raises error")
279275

280276
# filling anything but bool with bool casts to object
281277
expected_dtype = np.dtype(object) if dtype != bool else dtype
@@ -348,8 +344,6 @@ def test_maybe_promote_any_with_datetime64(
348344
or (box_dtype is None and is_datetime64_dtype(type(fill_value)))
349345
):
350346
pytest.xfail("mix of lack of upcasting, resp. wrong missing value")
351-
if not boxed and is_timedelta64_dtype(dtype):
352-
pytest.xfail("raises error")
353347

354348
# special case for box_dtype
355349
box_dtype = np.dtype(datetime64_dtype) if box_dtype == "dt_dtype" else box_dtype
@@ -490,9 +484,7 @@ def test_maybe_promote_any_numpy_dtype_with_datetimetz(
490484
fill_dtype = DatetimeTZDtype(tz=tz_aware_fixture)
491485
boxed, box_dtype = box # read from parametrized fixture
492486

493-
if dtype.kind == "m" and not boxed:
494-
pytest.xfail("raises error")
495-
elif dtype.kind == "M" and not boxed:
487+
if dtype.kind == "M" and not boxed:
496488
pytest.xfail("Comes back as M8 instead of object")
497489

498490
fill_value = pd.Series([fill_value], dtype=fill_dtype)[0]
@@ -549,8 +541,6 @@ def test_maybe_promote_any_with_timedelta64(
549541
else:
550542
if boxed and box_dtype is None and is_timedelta64_dtype(type(fill_value)):
551543
pytest.xfail("does not upcast correctly")
552-
if not boxed and is_datetime64_dtype(dtype):
553-
pytest.xfail("raises error")
554544

555545
# special case for box_dtype
556546
box_dtype = np.dtype(timedelta64_dtype) if box_dtype == "td_dtype" else box_dtype
@@ -622,9 +612,6 @@ def test_maybe_promote_any_with_string(any_numpy_dtype_reduced, string_dtype, bo
622612
fill_dtype = np.dtype(string_dtype)
623613
boxed, box_dtype = box # read from parametrized fixture
624614

625-
if is_datetime_or_timedelta_dtype(dtype) and box_dtype != object:
626-
pytest.xfail("does not upcast or raises")
627-
628615
# create array of given dtype
629616
fill_value = "abc"
630617

@@ -678,9 +665,6 @@ def test_maybe_promote_any_with_object(any_numpy_dtype_reduced, object_dtype, bo
678665
dtype = np.dtype(any_numpy_dtype_reduced)
679666
boxed, box_dtype = box # read from parametrized fixture
680667

681-
if not boxed and is_datetime_or_timedelta_dtype(dtype):
682-
pytest.xfail("raises error")
683-
684668
# create array of object dtype from a scalar value (i.e. passing
685669
# dtypes.common.is_scalar), which can however not be cast to int/float etc.
686670
fill_value = pd.DateOffset(1)

pandas/tests/io/excel/conftest.py

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
@pytest.fixture
99
def frame(float_frame):
10+
"""
11+
Returns the first ten items in fixture "float_frame".
12+
"""
1013
return float_frame[:10]
1114

1215

pandas/tests/io/test_gcs.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ def mock_get_filepath_or_buffer(*args, **kwargs):
108108
assert_frame_equal(df1, df2)
109109

110110

111-
@pytest.mark.skipif(
112-
td.safe_import("gcsfs"), reason="Only check when gcsfs not installed"
113-
)
111+
@td.skip_if_installed("gcsfs")
114112
def test_gcs_not_present_exception():
115113
with pytest.raises(ImportError) as e:
116114
read_csv("gs://test/test.csv")

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ numpydoc>=0.9.0
1717
nbconvert>=5.4.1
1818
nbsphinx
1919
pandoc
20-
dask-core
20+
dask
2121
toolz>=0.7.3
2222
fsspec>=0.5.1
2323
partd>=0.3.10

scripts/generate_pip_deps_from_conda.py

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def conda_package_to_pip(package):
4848

4949
break
5050

51+
if package in RENAME:
52+
return RENAME[package]
53+
5154
return package
5255

5356

0 commit comments

Comments
 (0)