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

Remove REPL dependency #3459

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SortingAlgorithms = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
2 changes: 1 addition & 1 deletion src/DataFrames.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module DataFrames

using Statistics, Printf, REPL
using Statistics, Printf
using Reexport, SortingAlgorithms, Compat, Unicode, PooledArrays
@reexport using Missings, InvertedIndices
using Base.Sort, Base.Order, Base.Iterators, Base.Threads
Expand Down
22 changes: 21 additions & 1 deletion src/other/index.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,26 @@ end
@inline Base.getindex(x::AbstractIndex, rx::Regex) =
getindex(x, filter(name -> occursin(rx, String(name)), _names(x)))

# Levenshtein Distance
topolarity marked this conversation as resolved.
Show resolved Hide resolved
# taken from https://github.com/JuliaLang/julia/blob/b5af119a6c608de43d6591a6c4129e9369239898/stdlib/REPL/src/docview.jl#L760-L776
function _levenshtein(s1, s2)
a, b = collect(s1), collect(s2)
m = length(a)
n = length(b)
d = Matrix{Int}(undef, m+1, n+1)

d[1:m+1, 1] = 0:m
d[1, 1:n+1] = 0:n

for i = 1:m, j = 1:n
d[i+1,j+1] = min(d[i , j+1] + 1,
d[i+1, j ] + 1,
d[i , j ] + (a[i] != b[j]))
end

return d[m+1, n+1]
end

# Fuzzy matching rules:
# 1. ignore case
# 2. maximum Levenshtein distance is 2
Expand All @@ -302,7 +322,7 @@ end
# Returns candidates ordered by (distance, name) pair
function fuzzymatch(l::Dict{Symbol, Int}, idx::Symbol)
idxs = uppercase(string(idx))
dist = [(REPL.levenshtein(uppercase(string(x)), idxs), x) for x in keys(l)]
dist = [(_levenshtein(uppercase(string(x)), idxs), x) for x in keys(l)]
sort!(dist)
c = [count(x -> x[1] <= i, dist) for i in 0:2]
maxd = max(0, searchsortedlast(c, 8) - 1)
Expand Down
Loading