diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index 3dba120c0c64b..42e12b9741d99 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -1718,9 +1718,21 @@ at `fsimpl1`_ for implementations built into ``fsspec`` and `fsimpl2`_ for those not included in the main ``fsspec`` distribution. -You can also pass parameters directly to the backend driver. For example, -if you do *not* have S3 credentials, you can still access public data by -specifying an anonymous connection, such as +You can also pass parameters directly to the backend driver. Since ``fsspec`` does not +utilize the ``AWS_S3_HOST`` environment variable, we can directly define a +dictionary containing the endpoint_url and pass the object into the storage +option parameter: + +.. code-block:: python + + storage_options = {"client_kwargs": {"endpoint_url": "http://127.0.0.1:5555"}}} + df = pd.read_json("s3://pandas-test/test-1", storage_options=storage_options) + +More sample configurations and documentation can be found at `S3Fs documentation +`__. + +If you do *not* have S3 credentials, you can still access public +data by specifying an anonymous connection, such as .. versionadded:: 1.2.0 diff --git a/pandas/tests/reshape/test_pivot.py b/pandas/tests/reshape/test_pivot.py index 1e122442cd40c..dcebd76cfd9ac 100644 --- a/pandas/tests/reshape/test_pivot.py +++ b/pandas/tests/reshape/test_pivot.py @@ -2613,9 +2613,36 @@ def test_pivot_not_changing_index_name(self): tm.assert_frame_equal(df, expected) def test_pivot_table_empty_dataframe_correct_index(self): - # GH 21932 + # GH#21932 df = DataFrame([], columns=["a", "b", "value"]) pivot = df.pivot_table(index="a", columns="b", values="value", aggfunc="count") expected = Index([], dtype="object", name="b") tm.assert_index_equal(pivot.columns, expected) + + def test_pivot_table_handles_explicit_datetime_types(self): + # GH#43574 + df = DataFrame( + [ + {"a": "x", "date_str": "2023-01-01", "amount": 1}, + {"a": "y", "date_str": "2023-01-02", "amount": 2}, + {"a": "z", "date_str": "2023-01-03", "amount": 3}, + ] + ) + df["date"] = pd.to_datetime(df["date_str"]) + + with tm.assert_produces_warning(False): + pivot = df.pivot_table( + index=["a", "date"], values=["amount"], aggfunc="sum", margins=True + ) + + expected = MultiIndex.from_tuples( + [ + ("x", datetime.strptime("2023-01-01 00:00:00", "%Y-%m-%d %H:%M:%S")), + ("y", datetime.strptime("2023-01-02 00:00:00", "%Y-%m-%d %H:%M:%S")), + ("z", datetime.strptime("2023-01-03 00:00:00", "%Y-%m-%d %H:%M:%S")), + ("All", ""), + ], + names=["a", "date"], + ) + tm.assert_index_equal(pivot.index, expected)