Skip to content

Commit bb63361

Browse files
authored
Remove REPL dependency (#3459)
1 parent 52d5a62 commit bb63361

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1818
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
1919
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
2020
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
21-
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
2221
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
2322
SortingAlgorithms = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
2423
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

src/DataFrames.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module DataFrames
22

3-
using Statistics, Printf, REPL
3+
using Statistics, Printf
44
using Reexport, SortingAlgorithms, Compat, Unicode, PooledArrays
55
@reexport using Missings, InvertedIndices
66
using Base.Sort, Base.Order, Base.Iterators, Base.Threads

src/other/index.jl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,26 @@ end
294294
@inline Base.getindex(x::AbstractIndex, rx::Regex) =
295295
getindex(x, filter(name -> occursin(rx, String(name)), _names(x)))
296296

297+
# Levenshtein Distance
298+
# taken from https://github.com/JuliaLang/julia/blob/b5af119a6c608de43d6591a6c4129e9369239898/stdlib/REPL/src/docview.jl#L760-L776
299+
function _levenshtein(s1, s2)
300+
a, b = collect(s1), collect(s2)
301+
m = length(a)
302+
n = length(b)
303+
d = Matrix{Int}(undef, m+1, n+1)
304+
305+
d[1:m+1, 1] = 0:m
306+
d[1, 1:n+1] = 0:n
307+
308+
for i = 1:m, j = 1:n
309+
d[i+1,j+1] = min(d[i , j+1] + 1,
310+
d[i+1, j ] + 1,
311+
d[i , j ] + (a[i] != b[j]))
312+
end
313+
314+
return d[m+1, n+1]
315+
end
316+
297317
# Fuzzy matching rules:
298318
# 1. ignore case
299319
# 2. maximum Levenshtein distance is 2
@@ -302,7 +322,7 @@ end
302322
# Returns candidates ordered by (distance, name) pair
303323
function fuzzymatch(l::Dict{Symbol, Int}, idx::Symbol)
304324
idxs = uppercase(string(idx))
305-
dist = [(REPL.levenshtein(uppercase(string(x)), idxs), x) for x in keys(l)]
325+
dist = [(_levenshtein(uppercase(string(x)), idxs), x) for x in keys(l)]
306326
sort!(dist)
307327
c = [count(x -> x[1] <= i, dist) for i in 0:2]
308328
maxd = max(0, searchsortedlast(c, 8) - 1)

0 commit comments

Comments
 (0)