Skip to content

Implement human-readable __repr__ methods for all main classes#568

Merged
vergauwenthomas merged 3 commits intodevfrom
copilot/fix-567
Sep 5, 2025
Merged

Implement human-readable __repr__ methods for all main classes#568
vergauwenthomas merged 3 commits intodevfrom
copilot/fix-567

Conversation

Copy link
Contributor

Copilot AI commented Sep 5, 2025

This PR implements human-readable __repr__ methods for all main MetObs classes to improve debugging and logging output.

Problem

Previously, many classes had technical or missing __repr__ methods that made debugging difficult:

# Before - not helpful for debugging
dataset = Dataset()
print(repr(dataset))  # "Instance of Dataset at 0x7fd96a48ffb0"

template = Template()
print(repr(template))  # "<metobs_toolkit.template.Template object at 0x...>"

station = Station("test", site, [sensordata])
print(repr(station))  # "Station instance of test"

Solution

All classes now have human-readable __repr__ methods that use the _id() method when available for unique identification:

# After - much more informative
dataset = Dataset()
print(repr(dataset))  # "Dataset(stations=0, obstypes=10)"

template = Template()
template.obscolumnmap = {"temp": "Temperature", "humidity": "RH"}
print(repr(template))  # "Template(obstypes=2, metacols=0)"

station = Station("WeatherStation_01", site, [sensordata])
print(repr(station))  # "Station(id=WeatherStation_01)"

Changes Made

  • Dataset: Shows meaningful counts instead of memory addresses
  • Station: Uses _id() method for consistent identification
  • SensorData: Uses _id() method showing station and obstype details
  • Obstype/ModelObstype: Uses _id() method with name and units
  • Template: Shows configuration summary with obstype/metadata counts
  • Analysis: Shows data summary with record/station/obstype counts

Benefits

  • Better debugging: Clear identification of objects in logs and debugger
  • Consistent format: All classes follow ClassName(key=value) pattern
  • Meaningful information: Shows object state rather than memory addresses
  • Logging clarity: Application logs now show useful context instead of cryptic references

All existing functionality is preserved while significantly improving the developer experience.

Fixes #567.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: vergauwenthomas <82087298+vergauwenthomas@users.noreply.github.com>
Copilot AI changed the title [WIP] Make a human readable __repr__ Implement human-readable __repr__ methods for all main classes Sep 5, 2025
@vergauwenthomas vergauwenthomas changed the base branch from master to dev September 5, 2025 09:49
@vergauwenthomas vergauwenthomas marked this pull request as ready for review September 5, 2025 09:50
Copilot AI review requested due to automatic review settings September 5, 2025 09:50
@vergauwenthomas vergauwenthomas merged commit 61b6a4c into dev Sep 5, 2025
9 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements human-readable __repr__ methods across all main MetObs classes to improve debugging and logging output. Instead of showing cryptic memory addresses or minimal object descriptions, the new representations provide meaningful information about object state and configuration.

Key changes include:

  • Standardized format using ClassName(key=value) pattern for consistency
  • Leveraging existing _id() methods where available for unique identification
  • Showing meaningful counts and status information instead of memory addresses

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/metobs_toolkit/dataset.py Updates both __str__ and __repr__ to show station and obstype counts
src/metobs_toolkit/station.py Changes to use _id() method for consistent identification
src/metobs_toolkit/sensordata.py Updates to use _id() method instead of manual string formatting
src/metobs_toolkit/obstypes.py Changes to use _id() method for obstypes identification
src/metobs_toolkit/template.py Adds new __repr__ method with basic instance description
src/metobs_toolkit/analysis.py Adds new __repr__ method showing record count
src/metobs_toolkit/gap.py Adds comprehensive __repr__ with gap details
src/metobs_toolkit/geedatasetmanagers.py Updates to show name and location instead of delegating to __str__

Comment on lines +130 to +132
def __repr__(self):
"""Return a string representation for debugging."""
return f"Template instance"
Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

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

The __repr__ method doesn't follow the established pattern used in other classes. According to the PR description, Template should show "obstypes and metadata counts" like Template(obstypes=2, metacols=0), but this implementation just returns a generic string. Consider implementing: return f"Template(obstypes={len(self.obscolumnmap)}, metacols={len(self.metadf_columns)})"

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +65 to +66


Copy link

Copilot AI Sep 5, 2025

Choose a reason for hiding this comment

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

Extra blank lines should be removed. There are unnecessary empty lines that don't follow the project's formatting standards.

Suggested change

Copilot uses AI. Check for mistakes.
vergauwenthomas added a commit that referenced this pull request Sep 5, 2025
* Modeltimeseries unit conv (#545)

* functionality for unit conversion in creation of modeltimeseries

* import at top

* update docstring of Modeltimeseries

* rename obstype to modelobstype for modeltimeseries

* black edits

* rename obstype attr

* typo

* fixing bugs

* Update the exaple to illustrate how units are converted

* Update tests and fixed bugs

* code review fixes

* black edits

* Update src/metobs_toolkit/modeltimeseries.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* minor version bump

* Add to_parquet and to_csv methods for Dataset and Station classes (#556)

* Initial plan

* Implement to_parquet and to_csv methods for Dataset and Station classes

Co-authored-by: vergauwenthomas <82087298+vergauwenthomas@users.noreply.github.com>

* Update documentation for to_parquet and to_csv methods

Co-authored-by: vergauwenthomas <82087298+vergauwenthomas@users.noreply.github.com>

* Apply black formatting to tests and validate implementation

Co-authored-by: vergauwenthomas <82087298+vergauwenthomas@users.noreply.github.com>

* fix the parquet implementation

* update the introduction example

* new subsection in api docs

* update docstrings

* fix formatting the csv test

* black edits

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: vergauwenthomas <82087298+vergauwenthomas@users.noreply.github.com>
Co-authored-by: Thomas Vergauwen <thomas.vergauwen@meteo.be>

* Update README.md to include conda install and badge (#555)

* Update README.md to include conda install and badge

* flags before package name convention

* update the docs to include conda install description

---------

Co-authored-by: Thomas Vergauwen <thomas.vergauwen@meteo.be>

* Implement CF-compliant netCDF serialization for xarray Datasets with nested attributes (#558)

* Initial plan

* Implement core netCDF serialization functionality with CF compliance

Co-authored-by: vergauwenthomas <82087298+vergauwenthomas@users.noreply.github.com>

* Complete netCDF serialization implementation with documentation and examples

Co-authored-by: vergauwenthomas <82087298+vergauwenthomas@users.noreply.github.com>

* version in seperate file to be accesible by other methods

* fix version in CI

* fix serializable cr datasets

* update docstrings

* add label conversion in the example

* fix bugs and xr tests

* fix version test

* fix the to_netcdf methods

* add to netcdf tests in the xr testing module

* code review style fixes

* black edits

* add to netcdf mode in the xarray topic

* to_netcdf in the introduction example

* sync version with pyproject

* bugfix

* fix merge issue with version

* add netcdf4

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: vergauwenthomas <82087298+vergauwenthomas@users.noreply.github.com>
Co-authored-by: Thomas Vergauwen <thomas.vergauwen@meteo.be>

* Parquet reader (#557)

* Adding tests and Parquet reader

* Adding parquet test data

* trigger tests

* fixed mismatch in tz + tests + docstring

* not intended for commit

* replace csvfilereader by the find_suitable_reader function

* update notebook

* bugfix

* black edits

* fix failing test

* fix tests

---------

Co-authored-by: nea-ppatel <patel_pratiman@nea.gov.sg>
Co-authored-by: Thomas Vergauwen <thomas.vergauwen@meteo.be>

* Qc on dataset error handling (#560)

* drop faulty files

* raise warnings if target station does not hold target obstype when qc on dataset level

* write test

* rename func

* black edits

* use tmp module in tests

* Fix NaTType error in frequency estimation for empty variable lists (#562)

* Initial plan

* Fix NaTType error in frequency estimation for empty timestamps

Co-authored-by: vergauwenthomas <82087298+vergauwenthomas@users.noreply.github.com>

* fix issue by selecting a minimum of 1 non-na values

* Delete tests/test_timestampmatcher.py

* test with nans

* black edits

* use warning instead of logging

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: vergauwenthomas <82087298+vergauwenthomas@users.noreply.github.com>
Co-authored-by: Thomas Vergauwen <thomas.vergauwen@meteo.be>

* Standardize warning formatting by converting operational warnings to logging (#565)

* Initial plan

* Replace warnings.warn with logger.warning for operational warnings

Co-authored-by: vergauwenthomas <82087298+vergauwenthomas@users.noreply.github.com>

* Update test to check for logging instead of warnings

Co-authored-by: vergauwenthomas <82087298+vergauwenthomas@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: vergauwenthomas <82087298+vergauwenthomas@users.noreply.github.com>

* fix warnings bug

* Check stations for obstype when GF is called on Dataset (#566)

* add filter_to_stations_with_target_obstype to GF methods on Dataset

* black edits

* black edits

* Implement human-readable __repr__ methods for all main classes (#568)

* Initial plan

* Implement human-readable __repr__ methods for all main classes

Co-authored-by: vergauwenthomas <82087298+vergauwenthomas@users.noreply.github.com>

* improve the __repr__ returns

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: vergauwenthomas <82087298+vergauwenthomas@users.noreply.github.com>
Co-authored-by: Thomas Vergauwen <thomas.vergauwen@meteo.be>

* reduce xarray restriction to >=2022.3.0

* review

* black edits

* use tempdir for parquet files in test

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Pratiman <31694629+pratiman-91@users.noreply.github.com>
Co-authored-by: nea-ppatel <patel_pratiman@nea.gov.sg>
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.

Make a human readable __repr__

3 participants