You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/12/01 05:57:39 UTC

[GitHub] [spark] xinrong-databricks commented on a change in pull request #34657: [SPARK-37511][PYTHON] Introduce TimedeltaIndex to pandas API on Spark

xinrong-databricks commented on a change in pull request #34657:
URL: https://github.com/apache/spark/pull/34657#discussion_r759874628



##########
File path: python/pyspark/pandas/indexes/timedelta.py
##########
@@ -0,0 +1,100 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+from typing import cast, no_type_check, Any
+from functools import partial
+
+import pandas as pd
+from pandas.api.types import is_hashable
+
+from pyspark import pandas as ps
+from pyspark._globals import _NoValue
+from pyspark.pandas.indexes.base import Index
+from pyspark.pandas.missing.indexes import MissingPandasLikeTimedeltaIndex
+from pyspark.pandas.series import Series
+
+
+class TimedeltaIndex(Index):
+    """
+    Immutable ndarray-like of timedelta64 data, represented internally as int64, and
+    which can be boxed to timedelta objects.
+
+    Parameters
+    ----------
+    data  : array-like (1-dimensional), optional
+        Optional timedelta-like data to construct index with.
+    unit : unit of the arg (D,h,m,s,ms,us,ns) denote the unit, optional
+        Which is an integer/float number.
+    freq : str or pandas offset object, optional
+        One of pandas date offset strings or corresponding objects. The string
+        'infer' can be passed in order to set the frequency of the index as the
+        inferred frequency upon creation.
+    copy  : bool
+        Make a copy of input ndarray.
+    name : object
+        Name to be stored in the index.
+
+    See Also
+    --------
+    Index : The base pandas Index type.
+
+    Examples
+    --------
+    >>> from datetime import timedelta
+    >>> ps.TimedeltaIndex([timedelta(1), timedelta(microseconds=2)])
+    TimedeltaIndex(['1 days 00:00:00', '0 days 00:00:00.000002'], dtype='timedelta64[ns]', freq=None)
+    """
+
+    @no_type_check
+    def __new__(
+        cls,
+        data=None,
+        unit=None,
+        freq=_NoValue,
+        closed=None,
+        dtype=None,
+        copy=False,
+        name=None,
+    ) -> "TimedeltaIndex":
+        if not is_hashable(name):
+            raise TypeError("Index.name must be a hashable type")
+
+        if isinstance(data, (Series, Index)):
+            # TODO(SPARK-37512): Support TimedeltaIndex creation given a timedelta Series/Index

Review comment:
       To support TimedeltaIndex creation given a timedelta Series/Index involves many changes in python/pyspark/pandas/data_type_ops/. Shall we implement that separately in https://issues.apache.org/jira/browse/SPARK-37512?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org