code: def test_max_per_category(self):
      docs_and_labels = DocsAndLabelsFromCorpusSample(
          self.parsed_corpus, max_per_category=2, seed=0
      )
      metadata = np.array(
          [
              "element 0 0",
              "element 1 0",
              "element 2 0",
              "element 3 0",
              "element 4 1",
              "element 5 1",
              "element 6 1",
              "element 7 1",
              "element 8 1",
              "element 9 2",
          ]
      )
      output = docs_and_labels.get_labels_and_texts_and_meta(metadata)
      self.assertTrue("texts" in output)
      self.assertTrue("labels" in output)
      self.assertTrue("meta" in output)
      self.assertTrue("extra" not in output)
      d = {}
      for text, lab, meta in zip(
          output["texts"], output["labels"], output["meta"]
      ):
          d.setdefault(lab, []).append(text)
      for lab, documents in d.items():
          self.assertLessEqual(len(documents), 2)
      json.dumps(d)
  
      docs_and_labels = DocsAndLabelsFromCorpusSample(
          self.parsed_corpus, max_per_category=2
      )
      output = docs_and_labels.get_labels_and_texts()
      self.assertTrue("texts" in output)
      self.assertTrue("labels" in output)
      self.assertTrue("meta" not in output)
      self.assertTrue("extra" not in output)
      d = {}
      for text, lab in zip(output["texts"], output["labels"]):
          d.setdefault(lab, []).append(text)
      for lab, documents in d.items():
          self.assertLessEqual(len(documents), 2)
      json.dumps(d)
  
      docs_and_labels = DocsAndLabelsFromCorpusSample(
          self.parsed_corpus, max_per_category=2
      ).use_non_text_features()
      output = docs_and_labels.get_labels_and_texts()
      self.assertTrue("texts" in output)
      self.assertTrue("labels" in output)
      self.assertTrue("meta" not in output)
      self.assertTrue("extra" in output)
      d = {}
      for text, lab in zip(output["texts"], output["labels"]):
          d.setdefault(lab, []).append(text)
      for lab, documents in d.items():
          self.assertLessEqual(len(documents), 2)
      json.dumps(d)
  
file_path: scattertext/scattertext/test/test_docsAndLabelsFromCorpus.py
imports: import json
  from unittest import TestCase
  import numpy
  import pandas
  from scattertext import CorpusFromParsedDocuments
  from scattertext import whitespace_nlp
  from scattertext.CorpusFromPandas import CorpusFromPandas
  from scattertext.DocsAndLabelsFromCorpus import DocsAndLabelsFromCorpus, DocsAndLabelsFromCorpusSample, CorpusShouldBeParsedCorpusException
  from scattertext.test.test_corpusFromPandas import get_docs_categories
  from scattertext.test.test_termDocMatrixFactory import build_hamlet_jz_corpus_with_meta
label_desc: Use image node_id 7 for calling the TestDocsAndLabelsFromCorpus obj's underlying member method code with example usage: obj.test_max_per_category() without return types