Skip to content
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

CLN: Refactor some sorting code in Index set operations #24533

Merged
merged 1 commit into from
Jan 1, 2019

Conversation

reidy-p
Copy link
Contributor

@reidy-p reidy-p commented Jan 1, 2019

This is a pre-cursor to #24521 and cleans up some of the sorting code in set operations on Index.

with tm.assert_produces_warning(warning_type):
# Python 3: Unorderable types
s3 = s1 * s2
s3 = s1 * s2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple of places where the above warning was given. But now that the safe_sort function is used the warning is no longer given because safe_sort tries to sort some "unorderable" types:

def sort_mixed(values):
# order ints before strings, safe in py3
str_pos = np.array([isinstance(x, string_types) for x in values],
dtype=bool)
nums = np.sort(values[~str_pos])
strs = np.sort(values[str_pos])
return np.concatenate([nums, np.asarray(strs, dtype=object)])
sorter = None
if PY3 and lib.infer_dtype(values) == 'mixed-integer':
# unorderable in py3 if mixed str/int
ordered = sort_mixed(values)
else:
try:
sorter = values.argsort()
ordered = values.take(sorter)
except TypeError:
# try this anyway
ordered = sort_mixed(values)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, this is the intent of the function

@jreback jreback added Reshaping Concat, Merge/Join, Stack/Unstack, Explode Compat pandas objects compatability with Numpy or Python functions labels Jan 1, 2019
@codecov
Copy link

codecov bot commented Jan 1, 2019

Codecov Report

Merging #24533 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #24533   +/-   ##
=======================================
  Coverage   31.88%   31.88%           
=======================================
  Files         166      166           
  Lines       52427    52427           
=======================================
  Hits        16714    16714           
  Misses      35713    35713
Flag Coverage Δ
#multiple 30.28% <0%> (ø) ⬆️
#single 31.88% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 091cfbb...f8bfb91. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Jan 1, 2019

Codecov Report

Merging #24533 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #24533   +/-   ##
=======================================
  Coverage   31.88%   31.88%           
=======================================
  Files         166      166           
  Lines       52427    52427           
=======================================
  Hits        16714    16714           
  Misses      35713    35713
Flag Coverage Δ
#multiple 30.28% <0%> (ø) ⬆️
#single 31.88% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 091cfbb...f8bfb91. Read the comment docs.

@jreback jreback added this to the 0.24.0 milestone Jan 1, 2019
@jreback jreback merged commit d659e7d into pandas-dev:master Jan 1, 2019
@jreback
Copy link
Contributor

jreback commented Jan 1, 2019

thanks @reidy-p

thoo added a commit to thoo/pandas that referenced this pull request Jan 1, 2019
* upstream/master:
  Make DTI[tz]._values and Series[tz]._values return DTA (pandas-dev#24534)
  CLN: Refactor some sorting code in Index set operations (pandas-dev#24533)
  Run isort (pandas-dev#24530)
  CI: fix db usage in CI (pandas-dev#24529)
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants