Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pptx/chart/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def categories(self):
Creating a chart from chart data having date categories will cause the chart to
have a |DateAxis| for its category axis.
"""
if not getattr(self, "_categories", False):
if not hasattr(self, "_categories"):
self._categories = Categories()
return self._categories

Expand Down
11 changes: 11 additions & 0 deletions tests/chart/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ def it_provides_access_to_its_categories(self, categories_fixture):
Categories_.assert_called_once_with()
assert categories is categories_

@pytest.mark.parametrize(
"label, number_format", ((date(2025, 4, 1), "yyyy-mm"), (12.5, "0.00"))
)
def it_keeps_the_category_number_format_set_before_the_first_label(self, label, number_format):
chart_data = CategoryChartData()
chart_data.categories.number_format = number_format

chart_data.add_category(label)

assert chart_data.categories.number_format == number_format

def it_can_add_a_category(self, add_cat_fixture):
chart_data, name, categories_, category_ = add_cat_fixture
category = chart_data.add_category(name)
Expand Down