8000 REF: implement _wrap_reduction_result by jbrockmendel · Pull Request #37660 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

REF: implement _wrap_reduction_result #37660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' of https://github.com/pandas-dev/pandas into cl…
…n-wrap_reduction
  • Loading branch information
jbrockmendel committed Oct 30, 2020
commit 297b2786fa7239e46fc6ad51968618d865622cea
28 changes: 20 additions & 8 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,10 +1267,16 @@ def min(self, axis=None, skipna=True, *args, **kwargs):
nv.validate_minmax_axis(axis, self.ndim)

if is_period_dtype(self.dtype):
result = self.to_timestamp("S").min(axis=axis, skipna=skipna)
if result is not NaT:
result = result.to_period(self.freq)
return result
# pass datetime64 values to nanops to get correct NaT semantics
result = nanops.nanmin(
self._ndarray.view("M8[ns]"), axis=axis, skipna=skipna
)
if result is NaT:
return NaT
result = result.view("i8")
if axis is None or self.ndim == 1:
return self._box_func(result)
return self._from_backing_data(result)

result = nanops.nanmin(self._ndarray, axis=axis, skipna=skipna)
if lib.is_scalar(result):
Expand All @@ -1294,10 +1300,16 @@ def max(self, axis=None, skipna=True, *args, **kwargs):
nv.validate_minmax_axis(axis, self.ndim)

if is_period_dtype(self.dtype):
result = self.to_timestamp("S").max(axis=axis, skipna=skipna)
if result is not NaT:
result = result.to_period(self.freq)
return result
# pass datetime64 values to nanops to get correct NaT semantics
result = nanops.nanmax(
self._ndarray.view("M8[ns]"), axis=axis, skipna=skipna
)
if result is NaT:
return result
result = result.view("i8")
if axis is None or self.ndim == 1:
return self._box_func(result)
return self._from_backing_data(result)

result = nanops.nanmax(self._ndarray, axis=axis, skipna=skipna)
if lib.is_scalar(result):
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2697,6 +2697,19 @@ def test_frame_ctor_datetime64_column(self):
df = DataFrame({"A": np.random.randn(len(rng)), "B": dates})
assert np.issubdtype(df["B"].dtype, np.dtype("M8[ns]"))

def test_dataframe_constructor_infer_multiindex(self):
index_lists = [["a", "a", "b", "b"], ["x", "y", "x", "y"]]

multi = DataFrame(
np.random.randn(4, 4),
index=[np.array(x) for x in index_lists],
)
assert isinstance(multi.index, MultiIndex)
assert not isinstance(multi.columns, MultiIndex)

multi = DataFrame(np.random.randn(4, 4), columns=index_lists)
assert isinstance(multi.columns, MultiIndex)

@pytest.mark.parametrize(
"input_vals",
[
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0