Skip to content

Conversation

@hyanwong
Copy link
Member

@hyanwong hyanwong commented Nov 28, 2025

Fixes #2637 - I remembered this issue when writing some recent tutorial material.

I went for the absolute size rather than percentage, and simply appended the codec type, rather than having a separate column, as it seems simpler:

I will add tests if this seems like the right format:

Screenshot 2025-11-28 at 21 06 21

@codecov
Copy link

codecov bot commented Nov 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.76%. Comparing base (28c9e48) to head (370022c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3343   +/-   ##
=======================================
  Coverage   89.76%   89.76%           
=======================================
  Files          29       29           
  Lines       31292    31302   +10     
  Branches     5738     5740    +2     
=======================================
+ Hits        28089    28099   +10     
  Misses       1794     1794           
  Partials     1409     1409           
Flag Coverage Δ
c-tests 86.77% <ø> (ø)
lwt-tests 80.38% <ø> (ø)
python-c-tests 87.12% <ø> (ø)
python-tests 98.85% <100.00%> (+<0.01%) ⬆️
python-tests-no-jit 33.49% <18.18%> (-0.02%) ⬇️
python-tests-numpy1 50.38% <100.00%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
python/tskit/trees.py 98.89% <100.00%> (ø)
python/tskit/util.py 99.30% <100.00%> (+0.02%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hyanwong
Copy link
Member Author

hyanwong commented Nov 28, 2025

I just updated to a different style, with percentages. I thought it best not to show anything if the metadata and schema are both empty. Dunno if I prefer percentages or bytes? If percentages, perhaps the title should be e.g. "Metadata (%)"?

Screenshot 2025-11-28 at 21 48 53

@hyanwong hyanwong force-pushed the md-size branch 2 times, most recently from 8e703c4 to 056973f Compare December 1, 2025 09:38
@jeromekelleher
Copy link
Member

Bytes are better. How does this interact with the old "has metadata" flag? What happens when there is metadata but there's no schema (I think I see what it is not from rereading the code, but it would really help to use some variables and not try to make everything maximally cryptic).

Some simple unit tests here based on the output of metadata_details covering the various possibilities would be sufficient.

@hyanwong
Copy link
Member Author

hyanwong commented Dec 2, 2025

I'll go with bytes then. This replaces the "has_metadata" column (which I think is the right way to go: if there is text in there, it means either a schema is set or there is metadata). I'm trying not to bloat the tables with lots of extra text / columns, so if we are going with bytes, how about

No metadata, no schema =
Some metadata, no schema = (XXX bytes)
No metadata, schema set = schema_codec
Some metadata, schema set = schema_codec (XXX bytes)

So e.g.

╔═══════════╤════╤═════════╤═════════════════╗
║Table      │Rows│Size     │ Metadata (size) ║
╠═══════════╪════╪═════════╪═════════════════╣
║Edges      │   6│200 Bytes│                 ║
╟───────────┼────┼─────────┼─────────────────╢
║Individuals│   2│ 80 Bytes│  json (90 Bytes)║
╟───────────┼────┼─────────┼─────────────────╢
║Migrations │   0│  8 Bytes│                 ║
╟───────────┼────┼─────────┼─────────────────╢
║Mutations  │   0│ 16 Bytes│          struct ║
╟───────────┼────┼─────────┼─────────────────╢
║Nodes      │   7│204 Bytes│       (50 Bytes)║
╟───────────┼────┼─────────┼─────────────────╢
║Populations│   1│224 Bytes│struct (50 Bytes)║
╟───────────┼────┼─────────┼─────────────────╢
║Provenances│   1│  1.1 KiB│                 ║
╟───────────┼────┼─────────┼─────────────────╢
║Sites      │   0│ 16 Bytes│                 ║
╚═══════════╧════╧═════════╧═════════════════╝

? Other suggestions welcome, obviously. I could put e.g. an empty marker (e.g. -) in the blank columns, but I think that's just more confusing than leaving it blank?

The alternative is to have 2 columns, labelled e.g. Metadata schema and Metadata size? In this case would we put "" in the first column for the empty schema, and e.g. "0" in the second for no metadata?

@jeromekelleher
Copy link
Member

I think it's confusing to omit the bytes value when it's empty, just say "0 Bytes". I think it's probably easier to understand if we have two columns all right.

@hyanwong
Copy link
Member Author

hyanwong commented Dec 5, 2025

How's this? Much simpler, and perhaps the percentages help, e.g. in another life,

Jerome: Quoting size as a percentage of table size would be useful I think.

If OK, I'll add tests

Screenshot 2025-12-05 at 14 09 08
╔═══════════╤════╤═════════╤════════╤═══════════════╗
║Table      │Rows│Size     │Metadata│Metadata size  ║
╠═══════════╪════╪═════════╪════════╪═══════════════╣
║Edges      │  42│  1.3 KiB│     raw│   0 Bytes (0%)║
╟───────────┼────┼─────────┼────────┼───────────────╢
║Individuals│   5│251 Bytes│    json│ 71 Bytes (28%)║
╟───────────┼────┼─────────┼────────┼───────────────╢
║Migrations │   0│  8 Bytes│     raw│   0 Bytes (0%)║
╟───────────┼────┼─────────┼────────┼───────────────╢
║Mutations  │  13│497 Bytes│     raw│   0 Bytes (0%)║
╟───────────┼────┼─────────┼────────┼───────────────╢
║Nodes      │  37│  1.2 KiB│    json│130 Bytes (11%)║
╟───────────┼────┼─────────┼────────┼───────────────╢
║Populations│   2│354 Bytes│    json│155 Bytes (44%)║
╟───────────┼────┼─────────┼────────┼───────────────╢
║Provenances│   5│  5.9 KiB│        │               ║
╟───────────┼────┼─────────┼────────┼───────────────╢
║Sites      │  12│316 Bytes│     raw│   0 Bytes (0%)║
╚═══════════╧════╧═════════╧════════╧═══════════════╝

@hyanwong hyanwong force-pushed the md-size branch 5 times, most recently from 0c5e46f to e9eb4eb Compare December 5, 2025 14:49
def metadata_codec(table):
if hasattr(table, "metadata_schema"):
schema = table.metadata_schema.schema
return "raw" if schema is None else schema.get("codec", "unknown")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the tests don't check if this value is correct? (eg, no examples of "unknown" codec)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good reason why logic like this should be spelled out longhand rather than aiming for maximally concise. Much easier to track test coverage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not even sure that we can have a schema with no codec, but as this is display code, I thought it better not to fail here, and I didn't really want to dive into understanding what was and wasn't acceptable as a schema. Bu I guess I should just allow this to fail if there's no codec then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it can't be tested then it shouldn't be in the code. You need to take responsibility here for understanding what you're putting in to the code - this is what being a maintainer entails.

if hasattr(table, "metadata_schema"):
schema = table.metadata_schema.schema
codec = schema["codec"] if schema else "raw"
codecs[codec] += 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here could check if it shows 0% for tables without metadata? And that the percent is <= 100%?

@jeromekelleher
Copy link
Member

Looks good. How does this look for the sc2ts tree sequence so we can see the output at scale?

Copy link
Member

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test following the modern modular approach please? If you're writing complicated logic in test code you're doing it wrong, as a rule of thumb.

I agree we should update existing tests minimally to capture the change in format, but do the testing of the actual conversion in standalone unit tests which are as stupidly simple as possible.

assert re.search(rf"║Time Units *│ *{ts.time_units}║", s)
for table in ts.tables.table_name_map:
assert re.search(rf"║{table.capitalize()} *│", s)
codecs = collections.defaultdict(int)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very much negative on this style of testing now - any complex logic in a test case is to be avoided.

I suggested testing these functions as follows

class TestMetadataCodecStr:
     def test_plain_table_collection(self):
             s = util.metadata_codec(tskit.TableCollection(1))
             assert s == "raw"

This is much more useful long term as well as being easier to write and review.

@hyanwong
Copy link
Member Author

hyanwong commented Dec 7, 2025

Looks good. How does this look for the sc2ts tree sequence so we can see the output at scale?

Like this:

Screenshot 2025-12-07 at 17 50 54
╔═════════════════════════╗
║TreeSequence             ║
╠═══════════════╤═════════╣
║Trees          │      316║
╟───────────────┼─────────╢
║Sequence Length│   29,904║
╟───────────────┼─────────╢
║Time Units     │     days║
╟───────────────┼─────────╢
║Sample Nodes   │2,482,157║
╟───────────────┼─────────╢
║Total Size     │408.1 MiB║
╚═══════════════╧═════════╝
╔═══════════╤═════════╤═════════╤════════╤═══════════════╗
║Table      │Rows     │Size     │Metadata│Metadata size  ║
╠═══════════╪═════════╪═════════╪════════╪═══════════════╣
║Edges      │2,748,838│ 83.9 MiB│     raw│   0 Bytes (0%)║
╟───────────┼─────────┼─────────┼────────┼───────────────╢
║Individuals│        0│ 24 Bytes│     raw│   0 Bytes (0%)║
╟───────────┼─────────┼─────────┼────────┼───────────────╢
║Migrations │        0│  8 Bytes│     raw│   0 Bytes (0%)║
╟───────────┼─────────┼─────────┼────────┼───────────────╢
║Mutations  │2,285,344│ 80.6 MiB│     raw│   0 Bytes (0%)║
╟───────────┼─────────┼─────────┼────────┼───────────────╢
║Nodes      │2,747,985│220.1 MiB│  struct│146.8 MiB (67%)║
╟───────────┼─────────┼─────────┼────────┼───────────────╢
║Populations│        0│  8 Bytes│     raw│   0 Bytes (0%)║
╟───────────┼─────────┼─────────┼────────┼───────────────╢
║Provenances│    1,135│  1.7 MiB│        │               ║
╟───────────┼─────────┼─────────┼────────┼───────────────╢
║Sites      │   29,893│729.8 KiB│     raw│   0 Bytes (0%)║
╚═══════════╧═════════╧═════════╧════════╧═══════════════╝

assert f"<td>{table_name.capitalize()}</td>" in html
if hasattr(table, "metadata_schema"):
schema = table.metadata_schema.schema
codec = schema["codec"] if schema else "raw"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer "bytes" here. "raw" implies something special?

def metadata_codec(table):
if hasattr(table, "metadata_schema"):
schema = table.metadata_schema.schema
return "raw" if schema is None else schema.get("codec", "unknown")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't have a schema without a codec.
As a general point of taste - defensive code is almost always indicating a lack of testing or some other smell. Unless it is to do with interfacing to the real world or data you don't control. Here we control everything so defensiveness is not wanted.


def metadata_size(table):
if hasattr(table, "metadata"):
frac = len(table.metadata) / table.nbytes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that table.nbytes can't be zero. Can you try to create one that is? If you can't then this is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metadata size in tables

4 participants