Skip to content

Commit

Permalink
replace is_datetime_or_timedelta_dtype (#316)
Browse files Browse the repository at this point in the history
* replace is_datetime_or_timedelta_dtype

Signed-off-by: kalyan <[email protected]>

* fix formatting

Signed-off-by: kalyan <[email protected]>

* fix import order

Signed-off-by: kalyan <[email protected]>

* update changelog

Signed-off-by: kalyan <[email protected]>

---------

Signed-off-by: kalyan <[email protected]>
Signed-off-by: kalyanr <[email protected]>
  • Loading branch information
rawwar authored Nov 13, 2023
1 parent 2c3b744 commit 7c2528b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Enable the model upload workflow to add model_content_size_in_bytes & model_content_hash_value to model config automatically @thanawan-atc ([#291](https://github.com/opensearch-project/opensearch-py-ml/pull/291))
- Update pretrained_models_all_versions.json (2023-10-18 18:11:34) by @dhrubo-os ([#322](https://github.com/opensearch-project/opensearch-py-ml/pull/322))
- Update model upload history - sentence-transformers/paraphrase-mpnet-base-v2 (v.1.0.0)(BOTH) by @dhrubo-os ([#321](https://github.com/opensearch-project/opensearch-py-ml/pull/321))
- Replaced usage of `is_datetime_or_timedelta_dtype` with `is_timedelta64_dtype` and `is_datetime64_any_dtype`([#316](https://github.com/opensearch-project/opensearch-py-ml/pull/316))

### Fixed
- Enable make_model_config_json to add model description to model config file by @thanawan-atc in ([#203](https://github.com/opensearch-project/opensearch-py-ml/pull/203))
Expand Down
12 changes: 8 additions & 4 deletions opensearch_py_ml/field_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
from pandas.core.dtypes.common import is_bool_dtype # type: ignore
from pandas.core.dtypes.common import (
is_datetime64_any_dtype,
is_datetime_or_timedelta_dtype,
is_float_dtype,
is_integer_dtype,
is_string_dtype,
is_timedelta64_dtype,
)
from pandas.core.dtypes.inference import is_list_like

Expand Down Expand Up @@ -91,7 +91,9 @@ def is_numeric(self) -> bool:

@property
def is_timestamp(self) -> bool:
return is_datetime_or_timedelta_dtype(self.pd_dtype)
return is_datetime64_any_dtype(self.pd_dtype) or is_timedelta64_dtype(
self.pd_dtype
)

@property
def is_bool(self) -> bool:
Expand Down Expand Up @@ -509,7 +511,7 @@ def _pd_dtype_to_os_dtype(pd_dtype) -> Optional[str]:
os_dtype = "boolean"
elif is_string_dtype(pd_dtype):
os_dtype = "keyword"
elif is_datetime_or_timedelta_dtype(pd_dtype):
elif is_datetime64_any_dtype(pd_dtype) or is_timedelta64_dtype(pd_dtype):
os_dtype = "date"
elif is_datetime64_any_dtype(pd_dtype):
os_dtype = "date"
Expand Down Expand Up @@ -794,7 +796,9 @@ def metric_source_fields(
pd_dtypes.append(np.dtype(pd_dtype))
os_field_names.append(os_field_name)
os_date_formats.append(os_date_format)
elif include_timestamp and is_datetime_or_timedelta_dtype(pd_dtype):
elif include_timestamp and (
is_datetime64_any_dtype(pd_dtype) or is_timedelta64_dtype(pd_dtype)
):
pd_dtypes.append(np.dtype(pd_dtype))
os_field_names.append(os_field_name)
os_date_formats.append(os_date_format)
Expand Down

0 comments on commit 7c2528b

Please sign in to comment.