Skip to content

Commit f80511f

Browse files
authored
Merge pull request #1027 from JuliaAI/dev
For a 1.9.2 release
2 parents 972ee95 + 16ad8a8 commit f80511f

File tree

6 files changed

+42
-29
lines changed

6 files changed

+42
-29
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MLJBase"
22
uuid = "a7f614a8-145f-11e9-1d2a-a57a1082229d"
33
authors = ["Anthony D. Blaom <[email protected]>"]
4-
version = "1.9.1"
4+
version = "1.9.2"
55

66
[deps]
77
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"

src/composition/learning_networks/nodes.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ _formula(stream::IO, X::AbstractNode, indent) =
270270
(print(stream, repeat(' ', indent));_formula(stream, X, 0, indent))
271271
_formula(stream::IO, X::Source, depth, indent) = show(stream, X)
272272
function _formula(stream, X::Node, depth, indent)
273-
operation_name = string(typeof(X.operation).name.mt.name)
274-
anti = max(length(operation_name) - INDENT)
273+
operation_name = simple_repr(X.operation)
274+
anti = max(length(operation_name) - INDENT, 0)
275275
print(stream, operation_name, "(")
276276
n_args = length(X.args)
277277
if X.machine !== nothing
@@ -287,9 +287,9 @@ function _formula(stream, X::Node, depth, indent)
287287
_formula(stream, X.args[k],
288288
depth + 1,
289289
indent + length(operation_name) - anti )
290-
k == n_args || print(stream, ",")
290+
print(stream, ",")
291291
end
292-
print(stream, ")")
292+
print(stream, crind(indent), ")")
293293
end
294294

295295
function Base.show(io::IO, ::MIME"text/plain", X::Node)
@@ -303,7 +303,7 @@ function Base.show(io::IO, ::MIME"text/plain", X::Node)
303303
_formula(io, X, 4)
304304
end
305305

306-
# for displaying withing other objects:
306+
# for displaying within other objects:
307307
function Base.show(stream::IO, object::Node)
308308
str = simple_repr(typeof(object)) * " $(handle(object))"
309309
mach = object.machine

src/operations.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ inverse_transform(mach::Machine; rows=:) =
108108
"must be explictly specified, "*
109109
"as in `inverse_transform(mach, X)`. "))
110110

111-
_symbol(f) = Base.Core.Typeof(f).name.mt.name
112-
113111
# catches improperly deserialized machines and silently fits the machine if it is
114112
# untrained and has no training arguments:
115113
function _check_and_fit_if_warranted!(mach)

src/show.jl

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,12 @@ show_as_constructed(object) = show_as_constructed(typeof(object))
9292
show_compact(object) = show_compact(typeof(object))
9393
show_handle(object) = false
9494

95-
# simplified string rep of an Type:
9695
function simple_repr(T)
97-
repr = string(T.name.name)
98-
parameters = T.parameters
99-
100-
# # add abbreviated type parameters:
101-
# p_string = ""
102-
# if length(parameters) > 0
103-
# p = parameters[1]
104-
# if p isa DataType
105-
# p_string = simple_repr(p)
106-
# elseif p isa Symbol
107-
# p_string = string(":", p)
108-
# end
109-
# if length(parameters) > 1
110-
# p_string *= ",…"
111-
# end
112-
# end
113-
# isempty(p_string) || (repr *= "{"*p_string*"}")
114-
115-
return repr
96+
# get rid of type parameters:
97+
output = split(repr(T), "{") |> first
98+
# get rid of qualifiers:
99+
output = split(output, ".") |> last
100+
return output
116101
end
117102

118103
# short version of showing a `MLJType` object:
@@ -165,7 +150,7 @@ function fancy(stream, object::MLJType, current_depth, depth, n)
165150
show(stream, object)
166151
else
167152
prefix = MLJModelInterface.name(object)
168-
anti = max(length(prefix) - INDENT)
153+
anti = max(length(prefix) - INDENT, 0)
169154
print(stream, prefix, "(")
170155
names = propertynames(object)
171156
n_names = length(names)

test/composition/learning_networks/nodes.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,17 @@ y = source(7)
481481
end
482482
end
483483

484+
@testset "show for nodes" begin
485+
# https://github.com/JuliaAI/MLJBase.jl/issues/1022
486+
X, y = make_blobs(3)
487+
X, y = source.([X, y])
488+
mach = machine(Standardizer(), X)
489+
W = transform(mach, X)
490+
str = sprint(show, MIME("text/plain"), W)
491+
# smoke test:
492+
@test contains(str, "formula:\n transform")
493+
end
494+
484495
end # module
485496

486497
true

test/show.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
using .Models
22

3+
module FooFoo
4+
5+
struct FooBar{T}
6+
x::T
7+
end
8+
9+
end
10+
11+
using .FooFoo
12+
13+
@testset "simple_repr" begin
14+
@test MLJBase.simple_repr(typeof(fill(3, 1))) == "Vector"
15+
@test MLJBase.simple_repr(typeof(FooFoo.FooBar(3))) == "FooBar"
16+
# with module qualifiers within type parameters
17+
object = FooFoo.FooBar(FooFoo.FooBar(rand(3)))
18+
T = typeof(object) # Main.FooFoo.FooBar{Main.FooFoo.FooBar{Vector{Float64}}}
19+
@test MLJBase.simple_repr(T) == "FooBar"
20+
end
21+
322
@testset "display of models" begin
423
io = IOBuffer()
524
show(io, KNNRegressor())

0 commit comments

Comments
 (0)