Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Adding Index time #34

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Draft: Adding Index time #34

wants to merge 10 commits into from

Conversation

JensZack
Copy link
Collaborator

@JensZack JensZack commented Jan 8, 2025

  • Adding mapping from index time to datetime
  • Currently an issue aligning time zones (fix in this PR)
  • Not handling "industrial time" yet, probably separate PR


@abc.abstractmethod

class CheckSchemaMixins:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

At some point while I was implementing the index time mapper, it made sense to pull out these mixins. Now keeping them seperate doesn't seem necessary, I can put these methods back in the base class if that would be preferable.

@@ -14,11 +14,10 @@ def __init__(self, model: IndexTimeRange) -> None:
self._model = model

def iter_timestamps(self) -> Generator[int, None, None]:
# TODO: port from dsgrid
raise NotImplementedError
yield from range(self._model.length)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to support 1-based ranges?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good point, will update

@@ -161,15 +161,18 @@ def list_time_columns(self) -> list[str]:


class IndexTimeRange(TimeBaseModel):
""" 0 based time index time representation """
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a start field to support 1-based ranges.



def check_mapping(from_schema: TableSchema, to_schema: TableSchema, from_config_type: Type, to_config_type: Type):
if isinstance(from_schema.time_config, from_config_type) and isinstance(to_schema.time_config, to_config_type):
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about removing the if?

return isinstance(from_schema.time_config, from_config_type) and isinstance(to_schema.time_config, to_config_type)


@abc.abstractmethod

class CheckSchemaMixins:
Copy link
Collaborator

Choose a reason for hiding this comment

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

@lixiliu What are the chances that we will have map to something other than datetime? If there is any reasonable chance of that, this name should probably include "to datetime."

class CheckSchemaMixins:
"""schema validation mixins."""

_to_time_config: DatetimeRange
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should these be instance attributes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I declared these class attributes so they could be used in the mixins without adding an init method

Copy link
Collaborator

Choose a reason for hiding this comment

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

But then what happens if someone creates two mappers at the same time? It's potentially very confusing for future developers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will move this back to the baseclass.

raise TableAlreadyExists(msg)

try:
with self._engine.connect() as conn:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this class use the common methods in the base class file? (apply_mapping, _apply_mapping)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, that would make sense. I was anticipating these methods to diverge between the different mappers, but it seems they are the same.

@@ -0,0 +1,37 @@
from util.mapper_test_helpers import get_datetime_schema, run_test, add_time_zone_data
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems problematic. Does it work when you run pytest from the base directory?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no, the pipeline seems to run from the tests dir. I can make it a relative import or do something else more efficient.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm surprised...I expected an ImportError from the base directory. If it works, I'm OK with it. But please follow the convention of standard imports, blank line, 3rd party imports, blank line, your imports.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

me too, but this is what I needed to do to get tests to run in the pipeline. I will update the import format.

) -> None:
# Ingest
metadata = MetaData()
with engine.connect() as conn:
Copy link
Collaborator

Choose a reason for hiding this comment

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

with engine.begin() as conn:

and then you don't have to commit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will do

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.

2 participants