Skip to content

Commit

Permalink
feat:(format): add pickle format (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoffrey Bolmier authored Jul 21, 2021
1 parent 980a506 commit 429b392
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
Binary file added examples/Pickle-model/model/model.pickle
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/Pickle-model/ormbfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
author: "Geoffrey Bolmier <[email protected]>"
format: Pickle
16 changes: 16 additions & 0 deletions pkg/model/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
FormatSKLearn Format = "SKLearn"
FormatXGBoost Format = "XGBoost"
FormatMLflow Format = "MLflow"
FormatPickle Format = "Pickle"
FormatOthers Format = "Others"
)

Expand Down Expand Up @@ -67,6 +68,8 @@ func (f Format) ValidateDirectory(rootPath string) error {
err = f.validateForXGBoost(modelFilePath, fileList)
case FormatMLflow:
err = f.validateForMLflow(modelFilePath, fileList)
case FormatPickle:
err = f.validateForPickle(modelFilePath, fileList)
case FormatOthers:
return nil
default:
Expand Down Expand Up @@ -275,3 +278,16 @@ func (f Format) validateForMLflow(modelPath string, files []os.FileInfo) error {
}
return nil
}

func (f Format) validateForPickle(modelPath string, files []os.FileInfo) error {
var pickleFileNum int32
for _, file := range files {
if path.Ext(file.Name()) == ".pickle" {
pickleFileNum++
}
}
if e := ValidateError(modelPath, "*.pickle", pickleFileNum); e != nil {
return e
}
return nil
}
6 changes: 6 additions & 0 deletions pkg/model/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ var _ = Describe("Format", func() {
Expect(err).To(BeNil())
})

It("Should validate Pickle format successfully", func() {
pickleFormat := model.FormatPickle
err := pickleFormat.ValidateDirectory("../../examples/Pickle-model")
Expect(err).To(BeNil())
})

It("Should validate Others for corruptted format successfully", func() {
others := model.FormatOthers
err := others.ValidateDirectory("../../test/Corrupt")
Expand Down

0 comments on commit 429b392

Please sign in to comment.