Skip to content

ENH: DTA to_pydatetime, time, timetz, date, iter support non-nano #47307

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 10 commits into from
Jun 15, 2022
Prev Previous commit
Next Next commit
BUG: concat not sorting mixed column names when None is included (#47331
)

* REGR: concat not sorting columns for mixed column names

* Fix none in columns

* BUG: concat not sorting column names when None is included

* Update doc/source/whatsnew/v1.5.0.rst

Co-authored-by: Matthew Roeschke <emailformattr@gmail.com>

* Add gh reference

Co-authored-by: Matthew Roeschke <emailformattr@gmail.com>
  • Loading branch information
2 people authored and jbrockmendel committed Jun 14, 2022
commit 5549bea415f7b8d8b2aeeb4c763ff6952b7e2ecb
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ Reshaping
- Bug in :func:`get_dummies` that selected object and categorical dtypes but not string (:issue:`44965`)
- Bug in :meth:`DataFrame.align` when aligning a :class:`MultiIndex` to a :class:`Series` with another :class:`MultiIndex` (:issue:`46001`)
- Bug in concanenation with ``IntegerDtype``, or ``FloatingDtype`` arrays where the resulting dtype did not mirror the behavior of the non-nullable dtypes (:issue:`46379`)
- Bug in :func:`concat` not sorting the column names when ``None`` is included (:issue:`47331`)
- Bug in :func:`concat` with identical key leads to error when indexing :class:`MultiIndex` (:issue:`46519`)
- Bug in :meth:`DataFrame.join` with a list when using suffixes to join DataFrames with duplicate column names (:issue:`46396`)
- Bug in :meth:`DataFrame.pivot_table` with ``sort=False`` results in sorted index (:issue:`17041`)
Expand Down
7 changes: 5 additions & 2 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1771,9 +1771,12 @@ def safe_sort(
def _sort_mixed(values) -> np.ndarray:
"""order ints before strings in 1d arrays, safe in py3"""
str_pos = np.array([isinstance(x, str) for x in values], dtype=bool)
nums = np.sort(values[~str_pos])
none_pos = np.array([x is None for x in values], dtype=bool)
nums = np.sort(values[~str_pos & ~none_pos])
strs = np.sort(values[str_pos])
return np.concatenate([nums, np.asarray(strs, dtype=object)])
return np.concatenate(
[nums, np.asarray(strs, dtype=object), np.array(values[none_pos])]
)


def _sort_tuples(values: np.ndarray) -> np.ndarray:
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/reshape/concat/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,12 @@ def __iter__(self):
tm.assert_frame_equal(concat(CustomIterator2(), ignore_index=True), expected)

def test_concat_order(self):
# GH 17344
# GH 17344, GH#47331
dfs = [DataFrame(index=range(3), columns=["a", 1, None])]
dfs += [DataFrame(index=range(3), columns=[None, 1, "a"]) for i in range(100)]
dfs += [DataFrame(index=range(3), columns=[None, 1, "a"]) for _ in range(100)]

result = concat(dfs, sort=True).columns
expected = dfs[0].columns
expected = Index([1, "a", None])
tm.assert_index_equal(result, expected)

def test_concat_different_extension_dtypes_upcasts(self):
Expand Down